1

I made a java application that compares screenshots taken from our staging environment against the production ones. The app fails due to different screenshot sizes.

How can I define the screenshot size? I am using the following code to generate the screenshot.

    final WebDriver driver = new FirefoxDriver();

    try {
        driver.manage().window().setSize(new Dimension(1024, 768));
        driver.get(link);
        File outputFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    ....
Potney Switters
  • 2,902
  • 4
  • 33
  • 51
  • 2
    Not with `OutputType.FILE`: [Javadoc] "TakesScreenshot makes a **best effort** depending on the browser to return the following in **order of preference**: 1) Entire page 2)Current window 3)Visible portion of the current frame 4)The screenshot of the entire display containing the browser." There is another `OutputType.BYTES`. But fitting the screenshot by working with raw bytes is a task I would not want to do. – Würgspaß Sep 30 '15 at 14:53

1 Answers1

0

As @Würgspaß mentioned in the comments, you can do this with OutputType.BYTE. Here is an example:

byte[] bytes = driver.getScreenshotAs(OutputType.BYTES);
BufferedImage full = ImageIO.read(new ByteArrayInputStream(bytes));
full.getSubimage(0, 0, 1200, 800);