Sushant Tavrawala
Sushant Tavrawala

Reputation: 55

TestNg Annotation - @AfterMethod does not run

I have 2 methods to be run in TestNg framework but my code executes only @Test and @AfterMethod does not execute.

code Screenshot is as per below

Please find output of result. As you can see, only AdminLogin method run and Closebrowser method failed and did not provide any result due to that it skipped other 2 test.

enter image description here

Upvotes: 0

Views: 2640

Answers (1)

Procrastinator
Procrastinator

Reputation: 2674

Possible solution:

Instead of trying to create a new Object, just initialize it everytime ion all the methods. So, instead of doing

WebDriver driver = new ChromeDriver();

Try using

driver = new ChromeDriver();

Also, for the @AfterMethod you can use annotation:

@AfterMethod(alwaysRun = true)

Upvotes: 1

Related Questions