27
Jun

How to capture screenshot in Selenium webdriver

package Screenshot;

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class ScreenshootGoogle {

@Test
public void TestJavaS1() {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();

driver.get(“http://Website with scroll.com/”);
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(src, new File(“C:/selenium/error.png”));
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}