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...