Screenshots are important to analyse the execution failures. It helps an automation tester to analyse what went wrong during execution. As one of the best automation testing services companies, we have also faced several challenges when troubleshooting test automation failures. Screenshot is a great reference document to recheck how the functionalities behaved previously and to identify false negatives from script failures.
In this blog article, we would like to share how to take screenshot in Selenium WebDriver using various commands.
Full Page Screenshot
In Selenium 4, you can take full page screenshot. This feature is very helpful to investigate failures in detail.
File file = ((FirefoxDriver)driver).getFullPageScreenshotAs(OutputType.FILE);
Note: As of now, full page screenshot works only for Firefox driver.
Sometimes you may need screenshot only for a specific element instead of capturing the entire page.
Full Page Screenshot using aShot
aShot is a WebDriver Screenshot utility. It takes a screenshot of the WebElement on different platforms (i.e. desktop browsers, iOS Simulator Mobile Safari, Android Emulator Browser).
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver); ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:///FullPageScreenshot.png"));
File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);