uk.ac.cam.automation.seleniumframework.screenshots.ScreenshotTaker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of seleniumframework Show documentation
Show all versions of seleniumframework Show documentation
A framework to enable test automation engineers to focus on writing tests rather than maintaining a testing
framework
package uk.ac.cam.automation.seleniumframework.screenshots;
import io.qameta.allure.Allure;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.remote.RemoteWebDriver;
import uk.ac.cam.automation.seleniumframework.driver.DriverManager;
import uk.ac.cam.automation.seleniumframework.properties.CommonProperties;
import uk.ac.cam.automation.seleniumframework.properties.PropertyLoader;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class ScreenshotTaker {
private static final boolean isScreenshotOff = Boolean.parseBoolean(PropertyLoader.getProperty(CommonProperties.SCREENSHOT_OFF));
public static void attachScreenshot() {
if (!isScreenshotOff && (DriverManager.getDriver() instanceof RemoteWebDriver)) {
Allure.getLifecycle().addAttachment(
LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd-MMM-yy_hh:mm:ss")),
"image/png",
"png",
getWebDriverScreenshot()
);
}
}
private static byte[] getWebDriverScreenshot() {
return (((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES));
}
}