Write the script in the following manner:
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.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class screenshot {
WebDriver driver;
@BeforeMethod
public void BM()
{
driver=new FirefoxDriver();
driver.get("http://google.com");
}
@Test
public void test()
{
try {
//Take the screenshot
File scrnsht =((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//Copy screenshot into a specific location
FileUtils.copyFile(scrnsht, new File("C:\\CANVAS\\k7.jpeg"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
@AfterMethod
public void AM()
{
driver.close();
driver.quit();
}
}
Where the screenshot will be generated and how can we know whether it is copied or not.?
ReplyDeleteHi Karthika,
ReplyDelete//Copy screenshot into a specific location
FileUtils.copyFile(scrnsht, new File("C:\\CANVAS\\k7.jpeg"));