Overview of Selenium Shutterbug - utility library to create customized screenshots using Selenium WebDriver and Java AWT
The most important part of test automation on any project is reporting. You may have thousands of tests running on dozens of devices, operating systems, browsers, but without descriptive, clear reporting the results all this effort is no more than waste of computation time and electricity.
A significant aspect of reporting results is to make self explanatory screenshots to be able to easy identify the reason of test failure and take appropriate actions - either raise a defect or fix the test.
Selenium Shutterbug was developed with above mentioned points in mind. The idea behind the project is to make testers life easier by enabling us 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.
Below are some basic examples of usage:
This is particularly useful while testing in Chrome, since it if following W3C definition of screenshot and takes screenshot of the top-level browsing context’s viewport only.
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();
As the result of chaining the operation on taken screenshot the following image is processed and saved to
The project is available in Maven Central
<dependency> <groupId>com.assertthat</groupId> <artifactId>selenium-shutterbug</artifactId> <version>x.x</version> </dependency>
Something new is coming... Stay up to date with AssertThat