检测testng @AfterMethod中的测试失败 [英] Detect test failure in testng @AfterMethod
本文介绍了检测testng @AfterMethod中的测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果测试失败,我想截取屏幕截图。我想将这个逻辑添加到用 @AfterMethod
注释的方法中,而不是用try / catch块包装所有测试方法。
I want to take a screenshot if a test fails. Rather than wrapping all test methods with try/catch blocks, I would like to add this logic to the method annotated with @AfterMethod
.
如果当前测试失败,如何在 @AfterMethod
注释的方法中检测到?
How can I detect in the method annotated with @AfterMethod
if the current test has failed?
推荐答案
如果使用 @AfterMethod
注释的方法具有 ITestResult
参数,那么TestNG将自动注入测试结果。 (来源: TestNG文档,第5.18.1节)
If the method annotated with @AfterMethod
has an ITestResult
parameter then TestNG will automatically inject the result of the test. (source: TestNG documentation, section 5.18.1)
这应该可以胜任:
@AfterMethod
public void tearDown(ITestResult result) {
if (result.getStatus() == ITestResult.FAILURE) {
//your screenshooting code goes here
}
}
这篇关于检测testng @AfterMethod中的测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文