All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.willhaben.willtest.config.DefaultScreenshotGenerator Maven / Gradle / Ivy

There is a newer version: 3.1.10
Show newest version
package at.willhaben.willtest.config;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;

/**
 * Takes a simple screenshot in case of an error. Only the viewport of the browser is captured.
 */
public class DefaultScreenshotGenerator implements ScreenshotGenerator {

    @Override
    public BufferedImage takeScreenshot(WebDriver webDriver) {
        TakesScreenshot takesScreenshot = (TakesScreenshot) webDriver;
        ByteArrayInputStream imageArrayStream = new ByteArrayInputStream(takesScreenshot.getScreenshotAs(OutputType.BYTES));
        try {
            return ImageIO.read(imageArrayStream);
        } catch (IOException e) {
            throw new RuntimeException("Can not parse screenshot to BufferedImage.", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy