diff --git a/src/main/java/com/assertthat/selenium_shutterbug/core/Configurations.java b/src/main/java/com/assertthat/selenium_shutterbug/core/Configurations.java new file mode 100644 index 0000000..ff6c1ea --- /dev/null +++ b/src/main/java/com/assertthat/selenium_shutterbug/core/Configurations.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016, Glib Briia Glib Briia + * Distributed under the terms of the MIT License + */ + +package com.assertthat.selenium_shutterbug.core; + +import com.assertthat.selenium_shutterbug.utils.web.Browser; +import com.assertthat.selenium_shutterbug.utils.web.Coordinates; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import java.util.function.Function; + +public class Configurations { + /** + * by default Shutterbug sets java.awt.headless=true + * to avoid exception "Could not initialize class sun.awt.X11GraphicsEnvironment" + * Method is to delete already set property + */ + public Configurations headless(boolean isHeadless) { + if (!isHeadless) { + System.clearProperty("java.awt.headless"); + } + return this; + } +} diff --git a/src/main/java/com/assertthat/selenium_shutterbug/core/Shutterbug.java b/src/main/java/com/assertthat/selenium_shutterbug/core/Shutterbug.java index c7aa66e..741a872 100644 --- a/src/main/java/com/assertthat/selenium_shutterbug/core/Shutterbug.java +++ b/src/main/java/com/assertthat/selenium_shutterbug/core/Shutterbug.java @@ -27,6 +27,10 @@ private Shutterbug() { } + static { + System.setProperty("java.awt.headless", "true"); + } + /** * Make screenshot of the viewport only. * To be used when screenshotting the page @@ -452,4 +456,8 @@ public static PageSnapshot shootFrame(WebDriver driver, String frameId) { WebElement frame = driver.findElement(By.id(frameId)); return shootFrame(driver, frame, CaptureElement.VIEWPORT, true); } + + public static Configurations configure() { + return new Configurations(); + } }