Screenshot function works only on first capture

19 views Asked by At

I am using a screenshot function, and for some reason it's sucesss to capture only the first screenshot, and after it all failed.

Comment: When I run each test seperatly, the capture is work

Function:

    public void screenShot(String folder, String name) {
        try {
            File screenshotsFolder = new File("src\\ExtFiles\\screenShots\\" + folder);
            if (!screenshotsFolder.exists()) {
                screenshotsFolder.mkdirs(); // Create the folder if it doesn't exist
            }

            File destFile = new File(screenshotsFolder, name + ".png");

            TakesScreenshot scrShot = ((TakesScreenshot) driver);
            File srcFile = scrShot.getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(srcFile, destFile);

        } catch (Exception e) {
            System.out.println("ERROR: Screenshot failed - " + e.getMessage());
            allure_FailLog("ERROR: Screenshot failed - " + e.getMessage());
        }
    }

Failed on line: File srcFile = scrShot.getScreenshotAs(OutputType.FILE);

Error:

ERROR: Screenshot failed - unknown error: unhandled inspector error: {"code":-32000,"message":"Unable to capture screenshot"}

Anyone knows what could be the reason?

Capture multiply screenshots at 1 run

0

There are 0 answers