简体   繁体   中英

Selenium Webdriver - Capture URL in screenshot using Robot

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

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM