我的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
但是我只想在我的afterMethod通过时才运行此@Test,而不是在@test失败时才运行。

最佳答案

引用TestNG's documentation:



您可以使用此参数来检查测试是否成功:

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

09-26 04:43