In this post, we will learn how to capture full length screenshot in 2 easy step.

We will be using shutterbug jar to capture it.

lets start.

Step 1- first of all add below shutterbug dependency in pom.xml file .

<dependency>

<groupId>com.assertthat</groupId>

<artifactId>selenium-shutterbug</artifactId>

<version>0.2</version>

</dependency>

 Step 2-

Please refer below piece of code, where ever you want to take screen-capture,  use it and full-length capture will be saved.

This code, will capture news.google.com page screenshot.

package mypackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.assertthat.selenium_shutterbug.core.Shutterbug;
import com.assertthat.selenium_shutterbug.utils.web.ScrollStrategy;
public class Fullpagescreencapture {
public static void main(String[] args) {
// TODO Auto-generated method stub
String exePath = "./Resources/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
WebDriver driver = new ChromeDriver();
driver.get("http://news.google.com");
driver.manage().window().maximize();
//name of screenshot along with location, in below line it is saving screenshot inside Screenshot folder which is inside project parent folder(/Screenshot)
Shutterbug.shootPage(driver,ScrollStrategy.BOTH_DIRECTIONS).withName("FullCapture").save("./Screenshot");
//driver.quit();
}
}

Where we should call this screenshot method-

1- If its a TestNG framework, call it inside listeners(ITestListner)

2- If it is a Cucumber framework, call it in Hooks.