package IntellipaatScreenshot;
import java.io.File;
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 IntellipaatScreenshot {
@Test
public void testIntellipaatScreenShot() throws Exception{
WebDriver driver ;
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
driver = new FirefoxDriver();
//goto url
driver.get("http://intellipaat.com/");
//Call take a screenshot function
this.takeSnapShot(driver, "c://test.png") ;
}
/*
* This function will take a screenshot
* @param webdriver
* @param fileWithPath
* @throws Exception
*/
public static void takeSnapShot(WebDriver webdriver,String fileWithPath) throws Exception{
//Convert web driver object to TakeScreenshot
TakesScreenshot scrShot =((TakesScreenshot)webdriver);
//Call getScreenshotAs method to create an image file
FileSrcFile=scrShot.getScreenshotAs(OutputType.FILE);
//Move image file to the new destination
File DestFile=new File(fileWithPath);
//Copy file at the destination
FileUtils.copyFile(SrcFile, DestFile);
}
}