Sunday, 19 February 2012

Take a screenshot with Selenium WebDriver for selenium automation testing


importjava.io.File;
importjava.io.IOException;
importorg.apache.commons.io.FileUtils;
importorg.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;


public classdadabhagwan_LearnSeleniumWithJasmine {

       public static voidmain(String[] args) throwsInterruptedException, IOException {
             
              WebDriver myDriver = newFirefoxDriver();
              myDriver.navigate().to("http://www.dadabhagwan.org/");
             
             
           File scrFile = ((TakesScreenshot)myDriver).getScreenshotAs(OutputType.FILE);
          

           FileUtils.copyFile(scrFile, newFile(System.getProperty("user.dir")+"\\src\\"+"myScreenshot"+".png"));

             
           System.out.println("myScreenshot.png is generated go to directory to check");
       }

}