When I try to take a screenshot, I added a scroll so that it can take a significant screenshot and not only the header. Right now, the picture is still taken from the header/top of the page.
Am I doing something wrong?
Screenshot method :
public void ScreenShot() {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“scroll(0,450);”);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(“yyyy-MM-dd HH_mm_ss”);
LocalDateTime now = LocalDateTime.now();
String destDir = System.getProperty(“user.dir”) + “/” + “test-output/ScreenShots”;
String FileName = “SoftAssertScreenshot_” + dtf.format(now) + “.png”;
String DestFile = destDir + “/” + FileName;
File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File ScreenshotName = new File(DestFile);
try {
FileUtils.copyFile(file, ScreenshotName);
} catch (IOException e) {
e.printStackTrace();
}
Reporter.log(“</br><font color=’#73a9d0′>***************Screen Of the error****************</font>”);
Reporter.log(“</br><img id=’ErrorResult’ src='” + DestFile + “‘ style=’width:600px’/>”);
}
Source: Read More