We know that capturing a screenshot is very important to a tester for validations ,As per the Automation testing in Selenium the java code required to capture a screenshot, To capture it the piece of code is given below.
package Spicejet;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
package Spicejet;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
private WebDriver driver;
File screenshot;
public void SpiceConnect() throws Exception {
driver = new FirefoxDriver();
// get the base url
driver.get("http://www.spicejet.com/");
//To maximize a window
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//click on the link spice connect
driver.findElement(By.linkText("SpiceConnect")).click();
/// user registration login page screen shot
try {
screenshot=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("C:\\Users\\MY PC\\Desktop\\Screenshots\\userregistration.png"));
}catch(Exception e){
System.out.println("Screen shot for registration page" + e);
}
driver.close();
}
No comments:
Post a Comment