简体   繁体   English

多变量方案大纲示例的黄瓜转换

[英]Cucumber Transforms for Multiple Variable Scenario Outline Examples

I have a set of functionally similar websites that I want to write cucumber specs for to drive both development, and selennium browser tests. 我有一组功能类似的网站,我想写一些黄瓜规范来推动开发和硒浏览器测试。 The site are in different languages and will have different URLs, but will have mainly the same features. 该网站使用不同的语言,具有不同的URL,但主要具有相同的功能。

An example scenario might be 一个示例场景可能是

Scenario Outline: Photo Gallery Next Action
  Given I visit a "<photo-gallery-page>"
  When I click "<next-button>" in the gallery
  Then the photo should advance
    Examples:
      | photo-gallery-page | next-button |
      | www.site1.com/photo-gallery | Next |
      | www.site2.com/la-galerie-de-photos | Suivant |

This is fine when I have a small number of scenarios and examples. 当我有少量场景和示例时,这很好。 However I'm anticipating hundred of scenarios and fairly regular launch of new sites. 但是,我预计会有数百种情况出现,并且相当定期地启动新站点。 I want to avoid having to edit each scenario to add examples when launching new sites. 我想避免在启动新站点时必须编辑每个方案以添加示例。

I think I need to store all my example variables in a per site configuration, so that I can run the same scenario against all sites. 我认为我需要将所有示例变量存储在每个站点配置中,以便可以对所有站点运行相同的方案。 Then I can add new configurations fairly easily and avoid editing all the scenario examples and making them unreadable. 然后,我可以轻松地添加新配置,避免编辑所有方案示例并使它们不可读。

site[:en].photo-gallery-page = 'www.site1.com/photo-gallery'
site[:fr].photo-gallery-page = 'www.site2.com/la-galerie-de-photos'
site[:en].next-button = 'Next'
site[:fr].next-button = 'Suivant'

One option would be to store this config somewhere, then generate the site specific gherkin files using a script. 一种选择是将该配置存储在某处,然后使用脚本生成特定于站点的小黄瓜文件。 I could then run these generated gherkins which would contain the required examples 然后,我可以运行这些生成的黄瓜,其中包含所需的示例

I'm wondering if there's an easier way. 我想知道是否有更简单的方法。 My other idea was if I can use table transforms to replace the example blocks. 我的另一个想法是,是否可以使用表转换来替换示例块。 I've had a read, but as far as I can tell I can only transform a table (and replace it with a custom code block) if it's an inline table within a step. 我已经读过书,但据我所知,如果它是一步中的内联表,则只能转换表(并用自定义代码块替换它)。 I can't transform an examples block in the same way. 我不能以相同的方式转换示例块。

Have I understood that correctly? 我理解正确吗? Any other suggestions on how best to achieve this? 关于如何最好地实现这一目标的任何其他建议?

I wonder if there's a better way... This all feels very brittle. 我想知道是否有更好的方法……这一切都感觉很脆弱。

What if: 如果:

Given I follow a link to the gallery "MyGallery"
And the gallery "MyGallery" contains the following photos:
|PhotoID|PhotoName|
|1      |MyPhoto1 |
|2      |MyPhoto2 |
And the photo "MyPhoto1" is displayed
When I view the next photo
Then the next photo "MyPhoto2" should be displayed

Note that you've taken out the notion of button names, etc. - implementation details that are presumably better defined in your step definitions. 请注意,您已经删除了按钮名称等概念-可能在步骤定义中更好地定义了实现细节。 The behaviour you're defining is simply going to a gallery, viewing an image, requesting the next one, viewing the next image. 您定义的行为只是去画廊,查看图像,请求下一个图像,查看下一个图像。 Define how in your step definitions. 定义如何在您的步骤定义。

There's some reading I found very useful on this topic at http://cuke4ninja.com/ . http://cuke4ninja.com/上有一些关于该主题的有用阅读材料。 Download the PDF and check out the web automation section (it details the web automation pyramid). 下载PDF并查看Web自动化部分(其中详细介绍了Web自动化金字塔)。

To address your configuration problem, maybe you could define some kind of config. 为了解决您的配置问题,也许您可​​以定义某种配置。 class and supply it to the step definition files via dependency injection. 类,并通过依赖注入将其提供给步骤定义文件。 You could make it site specific by loading from different config. 您可以通过从其他配置加载来使其特定于站点。 files as you suggested in its constructor. 文件,如您在其构造函数中建议的那样。 Step definitions could pull the relevant site specific data from the config. 步骤定义可以从配置中提取有关站点特定的数据。 class' properties. 类的属性。 I think this would make your scenario is more readable and less brittle. 我认为这将让你的情况是更具可读性更不易碎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使黄瓜测试中的“方案大纲”中的“示例”中的多行字符串起作用? - How to get multiline strings in Examples in Scenario Outline in cucumber tests to work? 具有特殊字符的黄瓜方案大纲 - Cucumber Scenario Outline with Special Characters 并行运行黄瓜方案大纲 - Running cucumber scenario outline in parallel 黄瓜场景大纲输入值中带引号 - Cucumber scenario outline input with quotes in the value 如何使用方案大纲运行相关的黄瓜方案 - How to run dependent cucumber scenarios with scenario outline 黄瓜方案大纲中的换行符导致错误 - Newline character in cucumber scenario outline causing error 在功能文件的“方案大纲:”表的“示例:”表中传递参数 - Passing parameter in “Examples:” table of “Scenario Outline:” in a feature file 带有示例表的“方案大纲”的黄瓜输出的实时格式 - Realtime formatting of cucumber output for 'Scenario Outline' with example table 从黄瓜步骤中拉出场景轮廓(或读取标签) - Pull scenario outline (or read a tag) from within cucumber step 如何从Ruby黄瓜方案大纲中生成可通过黄瓜报告正确使用的结果? - How to generate results from a Ruby Cucumber Scenario Outline that can be properly consumed by cucumber-reporting?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM