在Excel中存在多行,具有不同的数据集,我想为每个步骤截取屏幕截图
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\\screenshot1.png"));
driver.get("http://www.yahoo.com/");
File scrFile1 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile1, new File("c:\\tmp\\screenshot2.png"));
每个Excel行的重复方式如何。
好像我硬编码“Screenshot1,... 2等”的值最后,我将只获得2个屏幕截图,而不是每行记录的2个屏幕截图。
答案 0 :(得分:0)
创建FileName字符串而不是硬编码文件路径,您可以在屏幕截图文件名中传递行号,以便更好地识别屏幕截图文件。
File ScreenShot = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
StringBuilder FileName = new StringBuilder("C:\\tmp");
FileName.append(ScreenshotName);
FileName.append("_");
FileName.append(rownumber);
FileName.append(".jpeg");
FileUtils.copyFile(ScreenShot, new File(FileName.toString()));