[英]Run @AfterMethod only when my @Test is passed, not if @Test fails
我的afterMethod
由以下afterMethod
组成:
@AfterMethod(groups = { "Regression" })
public void afterMethod() {
// Setting driver used to false as this test case is pass
driverUsed.put("supportDriver", false);
System.out.println("Test case is pass");
}
我把驱动程序false
但是我希望只在我的@Test
通过时才运行afterMethod
,而不是@test
失败时。
引用TestNG的文档 :
任何
@AfterMethod
方法都可以声明一个ITestResult
类型的参数,它将反映刚刚运行的测试方法的结果。
您可以使用此参数来检查测试是否成功:
@AfterMethod(groups = { "Regression" })
public void afterMethod(ITestResult result) {
if (result.getStatus() == ITestResult.SUCCESS) {
// Setting driver used to false as this test case is pass
driverUsed.put("supportDriver", false);
System.out.println("Test case is pass");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.