Generating screenshots in Selenium

Generating screenshots for our test execution is an important part of the framework. It's as equally important as generating logs and reports.

The following code shows the traditional way of taking screenshots:

public class TakeScreenShot {
public void takeScreenPrint(String[] args) {
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")
+ "\src\main\resources\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.google.com");
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(src, new File("C:/selenium/error.png"));
}
catch (IOException e) {
throw new IOException();
}
}
}

This method is good only to take screenshots of visible areas of the screen. What if the page has a scroll bar and the full page is visible only if you scroll down?

This is where the AShot API comes to our rescue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.187.233