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.
Supported features:
The project is available in Maven Central
<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>
compile ('com.assertthat:selenium-shutterbug:1.6') {
exclude group: "org.seleniumhq.selenium", name: "selenium-java"
}
"com.assertthat" % "selenium-shutterbug" % "1.6" exclude("org.seleniumhq
.selenium", "selenium-java"),
Below are some basic examples of usage.
Shutterbug.shootPage(driver).save();
Shutterbug.shootPage(driver).save("C:\\testing\\screenshots\\");
Shutterbug.wait(visibilityOfElementLocated(By.id("someId")), 5).shootPage(driver, Capture.FULL).save();
Shutterbug.shootPage(driver, Capture.FULL_SCROLL).save();
Shutterbug.shootPage(driver, Capture.FULL_SCROLL ,500,true).save();
Shutterbug.shootPage(driver, Capture.FULL,true).save();
Shutterbug.shootElement(driver, element).save();
Shutterbug.shootPage(driver).equals(otherImage,0.1);
Shutterbug.shootPage(driver).equalsWithDiff(otherImage,pathToNewImage,0.1);
Shutterbug.shootPage(driver).equalsWithDiff(otherImage,pathToNewImage);
Shutterbug.shootPage(driver).withThumbnail(0.4).save();
frameID:driver.switchTo().defaultContent();
Shutterbug.shootFrame(driver, "frameID", CaptureElement.FULL_SCROLL).save();
driver.switchTo().defaultContent();
Shutterbug.shootFrame(driver, frameWebElement, CaptureElement.FULL_SCROLL).save();
Please note
- Currently full scrollable frame screenshot is only possible when the full frame is visible in the viewport. If frame size is greater than viewport size UnsupportedOperationException will be throws suggesting to use CaptureElement.VIEWPORT instead.
- Need to perform driver.switchTo().defaultContent(); before frame screensot. After the screenshot is taken driver will stay switched to the target frame.
Shutterbug.shootElement(driver, webElement, CaptureElement.HORIZONTAL_SCROLL).save();
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();
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
For details please read CONTRIBUTING
Code released under the MIT license
$ claude mcp add selenium-shutterbug \
-- python -m otcore.mcp_server <graph>