Niranjan
Niranjan

Reputation: 31

how to pass driver to testng listeners

I have two class one with test method and other one is Listener class. I am closing browser onTestFailure in listener, for this i need to pass driver from test method to listener. How can I pass driver to onTestFailure method in listener. Thanks.

Upvotes: 1

Views: 824

Answers (1)

juherr
juherr

Reputation: 5740

The one which closes the browser/driver should be the one which created it too.

What you can do is:

  1. In the listener: Create the driver
  2. In the listener: Push the driver into the ITestContext
  3. In the test class: Take the driver from the ITestContext and use it
  4. In the listener: Close the browser/driver

Upvotes: 1

Related Questions