Advertisement
SeleniumETrainR

How to Capture Screen shot using Java for selenium webdriver

Dec 13th, 2012
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. import org.apache.commons.io.FileUtils;
  6. import org.openqa.selenium.OutputType;
  7. import org.openqa.selenium.TakesScreenshot;
  8. import org.openqa.selenium.WebDriver;
  9. import org.openqa.selenium.firefox.FirefoxDriver;
  10.  
  11.  
  12. public class TakesScreenshotTest {
  13.  
  14.  
  15.  
  16. public static void main(String[] args) throws IOException {
  17. WebDriver myTestDriver = new FirefoxDriver();
  18. myTestDriver.get("http://tinyurl.com/6d7xz7k");
  19. myTestDriver.manage().window().maximize();
  20. myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
  21.  
  22. File scrFile = ((TakesScreenshot)myTestDriver).getScreenshotAs(OutputType.FILE);
  23. FileUtils.copyFile(scrFile, new File("c:\\careerbuilder.jpg"));
  24.  
  25. myTestDriver.quit();
  26. }
  27.  
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement