
utilities.ScreenshotHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of AUTOTESTIMATIC-JAVA Show documentation
Show all versions of AUTOTESTIMATIC-JAVA Show documentation
An open-source Selenium Java-based Test automation Framework that allows you to perform multiple actions
to test a web application's functionality, behaviour, which provides easy to use syntax,
and easy to set up environment according to the needed requirements for testing
package utilities;
import driverfactory.webdriver.WebDriver;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
public class ScreenshotHelper {
static String screenshotsDirectoryPath = "./screenshots";
private static final File screenshotsDirectory = new File(screenshotsDirectoryPath);
private ScreenshotHelper(){
}
public static Path captureScreenshot(WebDriver driver, String screenshotName){
if(!screenshotsDirectory.exists()){
boolean created = screenshotsDirectory.mkdirs();
if(created){
LoggingManager.info("Screenshots Directory Created");
}
}
Path destination = Paths.get("./screenshots", screenshotName + ".jpg");
byte[] byteArray = ((TakesScreenshot) driver.getDriver()).getScreenshotAs(OutputType.BYTES);
try {
Files.write(destination, byteArray, StandardOpenOption.CREATE);
} catch (IOException e) {
LoggingManager.error("Unable to capture Screenshot " + e.getMessage());
}
return destination;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy