0

In case, if my test method is using multiple browsers / multiple drivers , how do we identify where exactly the failure happened? (ie.,in which browser?)

For example, In a test, I launch two browsers and login to the application using two different credentials. First user submits the records and second user approves it. Failure can happen in any one of the browser. But how to identify which driver is causing the failure, so that we can capture the screen shot based on that.

If there are more than one drivers active, how do we identify the recently accessed driver?

Suggestions and answers are welcome.

Thanks in advance.

Best regards, Anand

Anand
  • 1

1 Answers1

0

If you must have 2 drivers whenever an error occurs you should catch it at the driver's level instead of the test's level using WebDriverListener.

import org.openqa.selenium.support.events.WebDriverEventListener;

public class DriverListener implements WebDriverEventListener {
     @Override
     public void onException(Throwable throwable, WebDriver driver) {
        // Code to take screenshot
     }
}

This way when an error occurs you can handle it and you also have a reference to the responsible WebDriver.

Kfir Doron
  • 229
  • 2
  • 5