Thursday, January 16, 2014

Taking Screenshot and Saving Screenshot (WebDriver)

Snippet for taking screenshot and saving it in specified path,

import java.io.File;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.apache.commons.io.FileUtils;

 @Test
 public void myTest() throws Exception {

        driver.get("http://www.google.com");
        driver.findElement(By.name("q")).sendKeys("Selenium");
   File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(scrFile, new File("F:\\Screenshots\\webscreen1.png")); 
}

No comments:

Post a Comment