Selenium 4 : How to capture screenshot

570 Views Asked by At

I need an After method to capture a screenshot compatible with Selenium 4 Java

1

There are 1 best solutions below

0
On BEST ANSWER
@After
public void tearDown(Scenario scenario) {
    if (scenario.isFailed()) {
        final byte[] screenshot = ((TakesScreenshot) Driver.get()).getScreenshotAs(OutputType.BYTES);
        scenario.attach(screenshot, "image/png", "screenshot");
    }


    Driver.closeDriver();

}