Sunday 13 November 2016

Screenshot in selenium

Hi,

Today we will be learning that how can we take screenshot using a selenium webdriver script.Screenshots are very useful in testing.It acts as a proof that a test case was run and executed.



SCRIPT FOR TAKING SCREENSHOT IN SELENIUM



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;


public class abcd {

public static void main(String ags[]) throws IOException
{
WebDriver driver=new FirefoxDriver();
driver.get("any website");

File file=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("d:\\abc.jpg"));
}
}

0 comments: