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

uk.ac.cam.automation.seleniumframework.screenshots.ScreenshotTaker Maven / Gradle / Ivy

Go to download

A framework to enable test automation engineers to focus on writing tests rather than maintaining a testing framework

There is a newer version: 6.2.1
Show newest version
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));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy