简体   繁体   中英

FirefoxDriver takes screenshots of different size

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);
    ....

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM