Skip to the content.

selenium-shutterbug

Build Status Maven Central

Synopsis

Selenium Shutterbug is a utility library written in Java for making screenshots using Selenium WebDriver and further customizing, comparing and processing them with the help of Java AWT.

The idea behind the project is to make testers life easier by enabling them to create descriptive screenshots which, in some cases, could be directly attached to the bug reports or serve as a source of information about system state at a specific moment of time.

Selenium WebDriver version 4+ support starts from version 1.6

Temporary workaround for Selenium v4+ in case of using RemoteWebDriverBuilder

Instead of:

` WebDriver driver = RemoteWebDriver.builder().address(“http://gridurl:4444”).addAlternative(new ChromeOptions()).build(); `

use

URL remoteAddress = new URL("http://gridurl:4444/wd/hub");
Tracer tracer = OpenTelemetryTracer.getInstance();
ClientConfig config = ClientConfig.defaultConfig().baseUrl(remoteAddress);
CommandExecutor executor = new HttpCommandExecutor(Collections.emptyMap(), config, new TracedHttpClient.Factory(tracer, org.openqa.selenium.remote.http.HttpClient.Factory.createDefault()));
CommandExecutor executorTraced =  new TracedCommandExecutor(executor, tracer);
WebDriver webDriver = new RemoteWebDriver(executorTraced, new ChromeOptions());

The reasoning is described in https://github.com/assertthat/selenium-shutterbug/issues/103

Supported features:

Installation

The project is available in Maven Central

Maven dependency
<dependency>
    <groupId>com.assertthat</groupId>
    <artifactId>selenium-shutterbug</artifactId>
    <version>1.6</version>
    <exclusions>
        <exclusion>
	    <groupId>org.seleniumhq.selenium</groupId>
	    <artifactId>selenium-java</artifactId>
	</exclusion>
     </exclusions>
</dependency>

Using Gradle
compile ('com.assertthat:selenium-shutterbug:1.6') {
    exclude group: "org.seleniumhq.selenium", name: "selenium-java"
    }
Using SBT
"com.assertthat" % "selenium-shutterbug" % "1.6" exclude("org.seleniumhq
.selenium", "selenium-java"),

Code Example

Below are some basic examples of usage.

Page screenshots

Screenshots comparison

Screenshots Thumbnails

Frame screenshots

Please note

Scrollable WebElements screenshots

Operations chaining

To demonstrate how it all can be pieced together the example follows:

    System.setProperty("webdriver.chrome.driver", "your path to  chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com/imghp");
        WebElement googleLogo = driver.findElement(By.id("hplogo"));
        WebElement searchBtn = driver.findElement(By.id("sblsbb"));
        WebElement searchBox = driver.findElement(By.className("gsfi"));

        searchBox.sendKeys("Testing");

        Shutterbug.shootPage(driver)
                .blur(searchBox)
                .highlight(searchBtn)
                .monochrome(googleLogo)
                .highlightWithText(googleLogo, Color.blue, 3, "Monochromed logo",Color.blue, new Font("SansSerif", Font.BOLD, 20))
                .highlightWithText(searchBox, "Blurred secret words")
                .withTitle("Google home page - " + new Date())
                .withName("home_page")
                .withThumbnail(0.7)
                .save("C:\\testing\\screenshots\\");
        driver.quit();

Available capture types

VIEWPORT - capture visible part of the viewport only

FULL - full page screenshot using devtools

FULL_SCROLL - full page/element/frame screenshot using scroll & stitch method

VERTICAL_SCROLL - vertical scroll page/element/frame screenshot using scroll & stitch method

HORIZONTAL_SCROLL - horizontal scroll page/element/frame screenshot using scroll & stitch method

Contributing

For details please read CONTRIBUTING

License

Code released under the MIT license