Wednesday 5 September 2018

Capture Full Screenshot in Selenium using Shutterbug


Selenium with the new upgrade 2.0 to 3.* had changed the way it works in the background. Starting with this upgrade, FirefoxDriver has stopped taking the full screenshot. There are many instances where user needs complete screenshot of the web page.
Many teams have worked on it & provided few open source libraries like AShot, ShutterBug etc.

Below code snippet would enable you to get the full screenshot using ShutterBug java library.

STEPS:



  1. Download the selenium-ShutterBug binaries from the below location.
    https://search.maven.org/search?q=a:selenium-shutterbug
  2. Add the libraries 'selenium-shutterbug.0.9.jar' in the java build path.
  3. Use the below code snippet to get the full screenshot.


System.setProperty("webdriver.chrome.driver","C:/Dvrs/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.amazon.in/");
driver.manage().window().maximize();

Snapshot<?> snapshot = Shutterbug.shootPage(driver, ScrollStrategy.WHOLE_PAGE, 100, true).withName("TestScreen");
snapshot.save("C:/AutomationProjects/screens/");

driver.close();



NOTE: ShutterBug library provides much more functionality apart from taking full screenshot.
(Reference: https://github.com/assertthat/selenium-shutterbug)

No comments:

Post a Comment