Reputation: 31
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?
Upvotes: 0
Views: 1587
Reputation: 13
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
Upvotes: 0
Reputation: 2099
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
Upvotes: 0