将黄瓜方案示例作为一种方案进行处理 [英] Handling cucumber scenario examples as one scenario

查看:61
本文介绍了将黄瓜方案示例作为一种方案进行处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用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 you could handle those like that:

    @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"));
}

这篇关于将黄瓜方案示例作为一种方案进行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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