如何使用Cucumber重新运行失败的场景?

Kal*_*yan 45 cucumber

我正在使用Cucumber进行测试.如何仅重新运行失败的测试?

And*_*lov 57

使用重新运行格式化程序运行Cucumber:

cucumber -f rerun --out rerun.txt
Run Code Online (Sandbox Code Playgroud)

它会将所有失败方案的位置输出到此文件.

然后你可以使用重新运行它们

cucumber @rerun.txt
Run Code Online (Sandbox Code Playgroud)

  • @JoeSusnick你不能使用&&因为如果第一个命令失败就会重新运行(这就是你需要的时候!)你想要|| (仅在失败时重新运行)或; (总是重新运行). (5认同)
  • 您可以使用&&将所有内容放在一个cmd行中(如果您只想启动它并走开),黄瓜-f rerun --out rerun.txt && cucumber @rerun.txt (3认同)

vkr*_*ams 6

这是我简单整洁的解决方案。

步骤1:使用编写您下面提到的黄瓜Java文件rerun:target/rerun.txt。黄瓜将失败的方案行号写入rerun.txt如下所示。

features/MyScenaios.feature:25
features/MyScenaios.feature:45
Run Code Online (Sandbox Code Playgroud)

稍后,我们可以在步骤2中使用该文件。将该文件命名为MyScenarioTests.java。这是运行带标记的方案的主文件。如果您的方案没有通过测试,请在目标目录下MyScenarioTests.java编写/标记它们rerun.txt

@RunWith(Cucumber.class)
@CucumberOptions(
    monochrome = true,
    features = "classpath:features",
    plugin = {"pretty", "html:target/cucumber-reports",
              "json:target/cucumber.json",
              "rerun:target/rerun.txt"} //Creates a text file with failed scenarios
              ,tags = "@mytag"
           )
public class MyScenarioTests   {

}
Run Code Online (Sandbox Code Playgroud)

步骤2:创建另一个方案文件,如下所示。可以这样说FailedScenarios.java。每当您发现任何失败的方案时,都运行此文件。该文件将target/rerun.txt用作运行方案的输入。

@RunWith(Cucumber.class)
@CucumberOptions(
    monochrome = true,
    features = "@target/rerun.txt", //Cucumber picks the failed scenarios from this file 
    format = {"pretty", "html:target/site/cucumber-pretty",
            "json:target/cucumber.json"}
  )
public class FailedScenarios {

}
Run Code Online (Sandbox Code Playgroud)

每当您发现任何失败的方案时,请在步骤2中运行文件