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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.