Snapshot generated by Selenium is very large

3

Good afternoon guys.

I'm using FirefoxDriver in version 2.53.0 and taking a snapshot of a site is generating an image with very large dimensions (111159x17555).

Does anyone know a way to fix this problem?

I've tried setting the browser dimension with the following code:

driver.manage().window().setSize(new Dimension(1366, 768));

And the problem persisted.

Here is an example of a snapshot that was generated.

Here is the code used to take the snapshot:

public static void saveScreenshot(WebDriver driver, String path) {
    File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(scrFile, new File(path));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
    
asked by anonymous 21.12.2016 / 15:17

1 answer

0

I do not know if it solves your case, but I could try based on my code that I use on another system. I really do not know if it solves your problem, it's worth the hint.

public BufferedImage screenshot(WebDriver driver) throws IOException {
    File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    BufferedImage fullImg = ImageIO.read(screenshot);
    return fullImg;
}

And I call a method to persist

public boolean persistScreenshot(BufferedImage image, String location) {
    try {
        File file = new File(location);
        if (file.exists()) {
            file.delete();
        }
        ImageIO.write(image, "png", file);
        return true;
    } catch (Exception e) {
        return false;
    }
}

The question is that I transform into a BufferedImage because I do not always need the direct persistence of it. Vla etalvez test if this would not solve the problem of it being redimensioned in a wrong way.

    
21.12.2016 / 19:15