Robot robot = new Robot();
BufferedImage screenShot = robot.createScreenCapture(new
Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(screenShot, "JPG", new File("ScreenShot.jpg"));
此代码将捕获测试用例失败时桌面屏幕上显示的内容的屏幕截图。但我需要用URL截取chromedriver浏览器屏幕的截图。如何在selenium中捕获错误场景?
答案 0 :(得分:0)
获取屏幕截图的正常方法
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"));
如果你需要失败的场景退出来捕获屏幕截图,你可以查看这篇文章How to capture Server Error Pages using selenium Web driver
答案 1 :(得分:0)