0
Robot robot = new Robot();
BufferedImage screenShot = robot.createScreenCapture(new 
Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(screenShot, "JPG", new File("ScreenShot.jpg"));

This code will capture the screenshot of whatever is present on the desktop screen when test cases fail. But I need to take screenshot of chromedriver browser screen with URL. How can I capture the error scenario in selenium?

SurajHolla
  • 31
  • 5

2 Answers2

0

Normal way to get screenshot

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

if you need failing scenario exits to capture a screen shot you can check this post How to capture Server Error Pages using selenium Web driver

kvizer
  • 13
  • 3
0

Chrome driver appears to be an issue for fullsize screenshots. You can see that people have written a work around here

Or you can reference the screenshot here

Josh Adams
  • 2,113
  • 2
  • 13
  • 25