如何使仅失败的场景在失败时自动再次运行?
这是我正在做的事情的一些线索:
feature/GM/TK/payment.feature:71
(指向失败的场景),但失败的场景不会自动重新运行。“TestRunner”java 文件
@RunWith(Cucumber.class)
@CucumberOptions(strict = true,
features = { "src/test/resources/" }, //feature file location
glue = { "com/test/stepdefs", "com.test.cucumber.hooks" }, //hooks and stepdef location
plugin = { "json:target/cucumber-report-composite.json", "pretty", "rerun:target/rerun.txt"}
)
public class CucumberTestRunner extends AbstractTestNGCucumberTests
{
}
从 rerun.txt 文件重新运行的“RunFailedTest”类
@RunWith(Cucumber.class)
@CucumberOptions(
strict = false,
features = { "@target/rerun.txt" }, //rerun location
glue = { "com/test/stepdefs", "com.test.cucumber.hooks" }, //hooks and stepdef location
plugin = {"pretty", "html:target/site/cucumber-pretty", "json:target/cucumber.json"}
)
class RunFailedTest
{
}
您可以通过使用 gherkin 和 qaf 来实现它,它会为失败的场景生成 testng XML 配置,您可以将其用于重新运行。它还支持通过设置
retry.count
属性在失败时重新运行场景。
使用 Cucumber + Maven + TestNG 首先,您不需要像您在问题中提到的那样“
@RunWith(Cucumber.class)
”,如果您使用的是TestNG,则只需要"@CucumberOptions"
。
当您开始执行测试时,所有场景失败都将根据 Runner 文件中提到的配置写入文件 "target/rerun.txt"
。
现在,您需要再创建一个 Runner 文件(例如 - “FailureRunner”),并在此文件中提供 "@target/rerun.txt"
的路径(这已经包含故障场景的详细信息)为 -> features = { "@target/rerun.txt" }
现在,您需要更新 TestNG.xml 文件并包含“FailureRunner”,如下所示 -
<class name="Class path of Your First Runner Class name" />
<class name="class path of FailureRunner Class" />
完成上述所有步骤并运行执行后,第一次执行将在
"target/rerun.txt"
中写入故障场景,之后,将执行“FailureRunner”类,它将拾取 "@target/rerun.txt"
文件,因此,将执行失败场景。
我已经以同样的方式执行了,效果很好,如果有帮助请告诉我!!
关于这个问题有什么消息吗?我现在也遇到同样的问题,如果你们已经解决了问题,请在这里添加..