I need to automate a shooter which takes a screenshot of the whole page of the website. I tried a solution, but only a part of the page is taken. Somebody can help? Below you see the code that I tried.
public void captureScreenshot(WebDriver driver, String screenshotName) {
// Take the screenshot only is the feature is activated
if (isActivate) {
try {
// before to take the screenshot
utils.sleep(1);
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File(dirPath + fileSep + screenshotName
+ "_" + strDateStamp + ".png"));
String ESCAPE_PROPERTY = "org.uncommons.reportng.escape-output";
System.setProperty(ESCAPE_PROPERTY, "false");
URL path = new File(dirPath + fileSep + screenshotName + "_"
+ strDateStamp + ".png").toURI().toURL();
String test = "<a href=" + path + "> click to open the screenshot "
+ screenshotName + "</a>";
Reporter.log(screenshotName + test + "<br>");
} catch (Exception e) {
System.out.println("Exception while taking screenshot " + e.getMessage());
}
}
}