at.willhaben.willtest.config.DefaultScreenshotGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Core classes with as few dependencies as possible
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