[英]Run @AfterMethod only when my @Test is passed, not if @Test fails
My afterMethod
consists of this: 我的
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");
}
where I am putting the driver false
我把驱动程序
false
But I want to run this afterMethod
only when my @Test
is passed, not when @test
fails. 但是我希望只在我的
@Test
通过时才运行afterMethod
,而不是@test
失败时。
To quote TestNG's documentation : 引用TestNG的文档 :
Any
@AfterMethod
method can declare a parameter of typeITestResult
, which will reflect the result of the test method that was just run.任何
@AfterMethod
方法都可以声明一个ITestResult
类型的参数,它将反映刚刚运行的测试方法的结果。
You can use this parameter to check if the test succeeded or not: 您可以使用此参数来检查测试是否成功:
@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.