在 TestNG/Selenium 中自动重启失败的测试用例
我正在使用 Selenium webdriver,在 Java 中与 TestNG 一起运行 X 数量的测试用例。
我希望任何测试用例一旦失败就自动重新启动(无论是从开始还是从故障点)。
我知道 TestNG 框架有以下方法
@Override
public void onTestFailure(ITestResult tr) {
log("F");
}
,但我不知道如何找出它是哪个测试用例,然后如何重新启动它。
I am using Selenium webdriver, in Java with TestNG to run an X amount of test cases.
What I would like, is for any test case to automatically restart (either from starting or from point of failure), as soon as it fails.
I know TestNG framework has the following method
@Override
public void onTestFailure(ITestResult tr) {
log("F");
}
but I do not know how to find out which testcase it was and then how would I restart it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想查看一个包含实际代码的示例,并在这里找到了它:
使用 TestNg 立即重新启动测试
观察如何一旦发生故障,以下测试将立即重新运行一次。
I wanted to see an example with actual code in it and found it here:
Restarting Test immediately with TestNg
Observe how the below tests will each be re-run once as soon as the failure happens.
来自 testng.org
每次测试在套件中失败时,TestNG 都会在输出目录中创建一个名为 testng-failed.xml 的文件。此 XML 文件包含仅重新运行这些失败的方法所需的信息,使您能够快速重现失败,而无需运行整个测试。
如果您想在失败后重新运行测试,则需要调用失败的方法。您可以从 ITestResult 对象获取该方法名称。
如果您想一起重新运行所有失败的测试用例,那么您可以在第一次执行后将 testng-failed.xml 作为输入 xml。
From testng.org
Every time tests fail in a suite, TestNG creates a file called testng-failed.xml in the output directory. This XML file contains the necessary information to rerun only these methods that failed, allowing you to quickly reproduce the failures without having to run the entirety of your tests.
If you want to rerun the test exactly after the failure you need to call the method that failed. You can get that method name from ITestResult object.
If you want to rerun all the failed test cases together, then you can give the testng-failed.xml as input xml after the first execution.