user8632458
user8632458

Reputation: 45

How to run a particular method if my test case failed(using TestNG)?

I'm writing test cases using TestNG.I want run a particular method after every failure test case.is there any way to run that method after every failure case?

Upvotes: 1

Views: 732

Answers (2)

Ishita Shah
Ishita Shah

Reputation: 4035

You can implement a method something with alwaysRun tag,

  @Test(alwaysRun = true)
  public void def()
  {
        -----
  }

It can be any annotation: Test, AfterTest, AfterClass

Upvotes: 1

Sameer Arora
Sameer Arora

Reputation: 4507

You can use ITestListener interface when you want to run a particular method after your test case failure.

You can find the ITestListener doc here: http://static.javadoc.io/org.testng/testng/6.11/org/testng/ITestListener.html

And you can refer to the following link for its implementation, its very helpful !! https://www.toolsqa.com/selenium-webdriver/testng-listeners/

Upvotes: 2

Related Questions