Some times we need to take full page screenshot in case of failures. In this post we will see how to take full page screenshots without using third party jars like Ashot , Shutterbug etc.
Use the below code and call it whenever u need to take full page screenshot.
In serenity report we will see full page screenshots like below :
Code:
public void takeFullPageScreenShot() {
try {
int heightInner = Integer
.parseInt(((JavascriptExecutor) getDriver()).executeScript("return window.innerHeight").toString());
int heightTotal = Integer.parseInt(((JavascriptExecutor) getDriver())
.executeScript("return document.documentElement.scrollHeight").toString());
int scrollInitial = 0;
int scrollFinal = heightInner - 150;
((JavascriptExecutor) getDriver())
.executeScript("window.scrollBy(0,-" + Integer.toString(heightTotal) + ")");
for (int i = 0; i < (heightTotal / scrollFinal); i++) {
Serenity.takeScreenshot();
((JavascriptExecutor) getDriver()).executeScript(
"window.scrollBy(" + Integer.toString(scrollInitial) + "," + Integer.toString(scrollFinal) + ")");
}
} catch (Exception e) {
logger.info(e.getMessage());
}
}
Use the below code and call it whenever u need to take full page screenshot.
In serenity report we will see full page screenshots like below :
Code:
public void takeFullPageScreenShot() {
try {
int heightInner = Integer
.parseInt(((JavascriptExecutor) getDriver()).executeScript("return window.innerHeight").toString());
int heightTotal = Integer.parseInt(((JavascriptExecutor) getDriver())
.executeScript("return document.documentElement.scrollHeight").toString());
int scrollInitial = 0;
int scrollFinal = heightInner - 150;
((JavascriptExecutor) getDriver())
.executeScript("window.scrollBy(0,-" + Integer.toString(heightTotal) + ")");
for (int i = 0; i < (heightTotal / scrollFinal); i++) {
Serenity.takeScreenshot();
((JavascriptExecutor) getDriver()).executeScript(
"window.scrollBy(" + Integer.toString(scrollInitial) + "," + Integer.toString(scrollFinal) + ")");
}
} catch (Exception e) {
logger.info(e.getMessage());
}
}