Wednesday 5 September 2018

Capture Full Screenshot in Selenium using AShot


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 AShot java library.

STEPS:



  1. Download the AShot binaries from the below location. https://mvnrepository.com/artifact/ru.yandex.qatools.ashot/ashot
  2. Add the libraries 'ashot-1.5.*.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();

Screenshot fpScreenshot = new AShot().shootingStrategy(
ShootingStrategies.viewportPasting(100)).takeScreenshot(driver);
ImageIO.write(fpScreenshot.getImage(), "PNG", new File("C:/screens/FPSshot3.png"));

driver.close();


NOTE: AShot library provide much more functionality apart from taking full screenshot.
(Reference: https://github.com/yandex-qatools/ashot)

No comments:

Post a Comment