How to take snapshot in Selenium WebDriver using java.

 import java.io.File;  
 import java.io.IOException;  
 import java.util.concurrent.TimeUnit;  
 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 Takesnapshot {  
   public static void main(String[] args) throws IOException {  
     // Intialize Web driver  
     WebDriver driver = new FirefoxDriver();  
     //Maximizw window  
     driver.manage().window().maximize();  
      //Launch website  
     driver.get("http://www.yahoo.com");  
     // wait for page loads  
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);  
     // Takes snapshort  
     File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);  
     // Save screen shot desired location  
     FileUtils.copyFile(scrFile, new File("screenshot.png"));  
     // close wbe driver  
     driver.quit();  
   }  
 }  

1 comment: