简体   繁体   English

Selenium Webdriver-使用机器人捕获屏幕快照中的URL

[英]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. 但是,我需要使用网址获取chromedriver浏览器屏幕的屏幕截图。 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 如果您需要通过失败的场景退出来捕获屏幕快照,则可以查看此文章如何使用Selenium Web驱动程序捕获服务器错误页面

Chrome driver appears to be an issue for fullsize screenshots. Chrome驱动程序似乎是全屏截图的问题。 You can see that people have written a work around here 您可以看到人们在这里写了一篇作品

Or you can reference the screenshot here 或者您可以在这里参考屏幕截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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