只有在@Test通过时才运行@AfterMethod,而不是在@Test失败时运行



我的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");
}
}

最新更新