How might you consequently click a screen capture at whatever point an exception happens?

862    Asked by NeerajNair in QA Testing , Asked on Jan 25, 2020
Answered by Neeraj Nair

For this you should utilize the class and need to actualize the technique for the interface. See the code model given beneath.

WebDriver browser = new FirefoxDriver();

EventFiringWebDriver eventDriver = new EventFiringWebDriver(browser).register(new AbstractWebDriverEventListener() {

  @Override

  public void onException(Throwable throwable, WebDriver browser) {

    // Take the screenshot using the Webdriver.

    File screen = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

    // Now you can copy the screenshot somewhere on your system.

    FileUtils.copyFile(screen, new File("c:Selenium Testing Questionsscreen.png"));

  }

});

try {

  eventDriver.findElement(By.id("test"));

  fail("Caught the Expected exception."); // Intentionally causing the exception for demo.

} catch (NoSuchElementException e) {

  // Triggering point for the event.

}



Your Answer

Interviews

Parent Categories