将黄瓜场景示例作为一种场景处理
我在使用 Cucumber 时遇到了问题 - 现在我正在做一个移动自动化并且我有使用场景大纲的功能 - 我在场景中有几个变量:
I'm having a problem with Cucumber - right now I'm doing a mobile automation and I have features that use scenario outlines - I have a few variables in the scenario :
场景大纲:菜单项
Given the user is on the hamburger menu
And the language is <language>
Then menu item is <menu item>
Examples:
| menu item | language |
| Search | EN |
| Zoeken | NL |
| Recherche | FR |
| Saved properties | EN |
| Bewaarde zoekertjes | NL |
| Biens sauvés | FR |
| Saved searches | EN |
| Bewaarde zoekacties | NL |
| Recherches sauvées | FR |
| Settings | EN |
| Instellingen | NL |
| Paramètres | FR |
当我运行这个场景时,它会为每一行重新启动应用程序(在某些情况下这可能很好,但不是这样),这非常耗时.有没有办法指出应用程序何时应该重新启动应用程序以及何时应该继续执行示例?
And when I run this scenario it restarts the application for every row (in some cases that might be good, but not this) which is very time consuming. Is there a way to point out when the application should restart the application and when it should just continue along the examples ?
我尝试将示例作为列表处理,但没有帮助.
I tried handling the examples as a List but that did not help.
@Then("^menu item is (.*)$")
public void menuItem(List<String> menuItems){
for(String menuItem : menuItems)
Assert.assertEquals( menuItem, Common.getElementAttributeByName(menuItem,"text"));
}
正如 Thomas Sundberg 提到的,您有很多选择.但是对于您的特定情况,您可能需要保持所有规格不变,
As Thomas Sundberg mentioned you have many options. However for your particular case as you might need to keep all the specs as is and
那么他应该能够在所有语言上做到这一点
Then he should be able to do it on all languages
不够具体.您可以像这样重写场景:
is not enough specific. You might rewrite the scenario like this:
Scenario: Menu items
Given the user is on the hamburger menu
Then the possible menu items are
| Search | EN |
| Zoeken | NL |
| Recherche | FR |
| Saved properties | EN |
| Bewaarde zoekertjes | NL |
| Biens sauvés | FR |
| Saved searches | EN |
| Bewaarde zoekacties | NL |
| Recherches sauvées | FR |
| Settings | EN |
| Instellingen | NL |
| Paramètres | FR |
然后你可以处理那些:
@Then("^the possible menu items are$")
public void menuItems(Map<String, String> menuItems){
for(Map.Entry<String, String> menuItem:menuItems.entrySet()) {
switchToLanguage(menuItem.getValue());
Assert.assertEquals( menuItem.getKey(), Common.getElementAttributeByName(menuItem.getKey(),"text"));
}