![JAR search and dependency download from the Maven repository](/logo.png)
software.reinvent.headless.chrome.HeadlessDriverUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of headless-chrome Show documentation
Show all versions of headless-chrome Show documentation
Implementation of the headless chrome with chromedriver and selenium.
package software.reinvent.headless.chrome;
import com.assertthat.selenium_shutterbug.core.PageSnapshot;
import com.assertthat.selenium_shutterbug.core.Shutterbug;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import static com.assertthat.selenium_shutterbug.utils.web.ScrollStrategy.BOTH_DIRECTIONS;
/**
* Created on 05.01.2017.
*
* @author Leonard Daume
*/
public class HeadlessDriverUtils {
public static void takeFullScreenshot(WebDriver webDriver, File pngFile) throws IOException {
takeFullScreenshot(webDriver, pngFile, null);
}
public static void takeFullScreenshot(WebDriver webDriver, File pngFile, By... highlights)
throws IOException {
final PageSnapshot pageSnapshot = Shutterbug.shootPage(webDriver, BOTH_DIRECTIONS);
if (ArrayUtils.isNotEmpty(highlights)) {
Arrays.stream(highlights)
.map(webDriver::findElements)
.flatMap(Collection::stream)
.forEach(pageSnapshot::highlight);
}
FileUtils.forceMkdirParent(pngFile);
pageSnapshot.withName(pngFile.getName());
pageSnapshot.save(pngFile.getParent());
FileUtils.deleteQuietly(pngFile);
FileUtils.moveFile(new File(pngFile.getPath() + ".png"), pngFile);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy