5

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.

1 Answer 1

10

To quote TestNG's documentation:

Any @AfterMethod method can declare a parameter of type ITestResult, 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"); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.