量角器 - 如何为不同的测试重用相同的规范文件 [英] Protractor - how to reuse the same spec file for different tests

查看:56
本文介绍了量角器 - 如何为不同的测试重用相同的规范文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Protractor conf.js 文件中,我想多次重复使用相同的规范文件;然而,这似乎是不可能的.

In my Protractor conf.js file, I'd like to re-use the same spec files multiple times; however, it's seems to not be possible.

一些背景:

我们正在从 JSON 文件中读取测试用例,启动报告,然后测试网格结果和各种 DOM 元素.

We are reading test cases from a JSON file, launching reports, then testing grid results and various DOM elements.

所有报告都具有相同的格式.主要区别在于报表标题、数据列、实际数据结果等.

All reports have the same format. The primary differences lie in the report titles, data columns, actual data results, etc.

所以在我的 conf.js 文件中,理想情况下我想多次重复使用相同的规范文件 - 但我的理解是我不能这样做.

So in my conf.js file, ideally I'd like to re-use the same spec files multiple times - but my understanding is that I cannot do this.

例如,我的规格数组:

specs: [
      'spec/report1-spec.js',
      'spec/report-grid-details-spec.js',
      'spec/report2-spec.js',
      'spec/report-grid-details-spec.js',
      'spec/report3-spec.js',
      'spec/report-grid-details-spec.js',
 ]

我读过这篇文章(http://ramt.in/how-to-run-identical-jasmine-specs-multiple-times-with-protractor/ ),您可以在其中将规范文件移动到 node 模块code>,但是 1) 我不想将所有规范文件都移到那里,并且 2) 当我将一个规范文件移动到一个模块导出文件.

I've read this post (http://ramt.in/how-to-run-identical-jasmine-specs-multiple-times-with-protractor/ ) where you can move your spec files into a node module, but 1) I don't want to move all specs files there, and 2) it doesn't work anyway when I move even one spec file into a module export file.

如果我做不到,那么我只需将我的 report-grid-details-spec.js 代码移动到一个公共的 page object 文件中并调用需要时随时使用.

If I can't do it, then I'll just move my report-grid-details-spec.js code into a common page object file and call it whenever it's needed.

只是想知道是否有人找到了解决方案来解决在一个 conf.js 配置中多次重复使用规范文件的需求.

Just wondering if anyone out there has found a solution to this need to re-use spec files multiple times in one conf.js configuration.

谢谢,鲍勃

推荐答案

如果我做不到,那么我只需将我的 report-grid-details-spec.js 代码移动到一个公共页面对象文件中,并在需要时调用它.

If I can't do it, then I'll just move my report-grid-details-spec.js code into a common page object file and call it whenever it's needed.

这可能是解决问题的最简单方法.不过,我喜欢将规范放入模块的想法 - 这有利于整体的可重用性.

This would probably be the easiest way to approach the problem. Though, I like the idea of putting specs into modules - it is a plus to reusability overall.

问题是,jasmine 不允许在单个测试运行中执行相同的测试.而且,据我所知,没有简单的方法可以改变这种行为.

The thing is, jasmine does not allow executing the same test in a single test run. And, from what I understand, there is no easy way to change the behavior.

可能的解决方法之一是完全重新启动量角器,从而重新创建 jasmine 测试环境,以便下一个 report-grid-details-spec.js 将在新的 jasmine 环境中运行 -这是 protractor-flake 项目 用来重试的东西失败的测试(它基本上重新启动 protractor 通过命令行将失败的规范作为逗号分隔的列表传递给 specs 参数,source).

One of the possible workarounds is to completely restart protractor and, hence, recreate the jasmine testing environment so that the next report-grid-details-spec.js would run in a new jasmine environment - this is something that protractor-flake project uses to retry the failing tests (it basically restarts protractor through command-line passing the failing specs as a comma-separated list to the specs argument, source).

这篇关于量角器 - 如何为不同的测试重用相同的规范文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆