My afterMethod
consists of this:
@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
But I want to run this afterMethod
only when my @Test
is passed, not when @test
fails.
To quote TestNG's documentation:
Any
@AfterMethod
method can declare a parameter of typeITestResult
, which will reflect the result of the test method that was just run.
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");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With