Selenium Webdriver:自动重复成功的方案

时间:2015-03-20 09:29:07

标签: java selenium webdriver cucumber gherkin

我使用基于Java / Gherkin / Cucumber的Selenium Webdriver测试。

我有一个测试运行,我想多次运行,而不必多次重启场景。

Gherkin脚本是这样的:

Given the user opens a browser
Then the user fills in the form
Then the user repeats the filling of the form *5* times 

这样,如果我要填写10个表格,我可以用10替换5,按播放,然后拿啤酒。

这是完全可能还是我只需要手动重新运行场景5次?

1 个答案:

答案 0 :(得分:1)

首先,您可以简化您的Gherkin场景,例如:

 Given the user opens a browser

 Then the user fills in the form 5 times

在这种情况下,您可以生成方法,在第二种方法中,您可以添加循环,例如:

[然后(@“用户填写表格(。*)次”)]

public void ThenTheUserFillsInTheForm(int nrOfTimes)   
{        
    for(int i = 0; i < nrOfTimes; i++)
    {

      //user fills in the form

    }
}