我目前正在努力捕获iOS上的截图,以便使用
java和junit进行appium测试.在测试完成之前,它会运行此代码以在杀死连接之前获取屏幕上最后一个可见的内容
@After
public void tearDown() throws Exception {
if (platform.equals(iOS)) {
captureScreenshot(testName.getMethodName());
}
driver.quit();
}
@SuppressWarnings("Augmenter")
public void captureScreenshot(String testName) {
String imagesLocation = "target/surefire-reports/screenshot/" + platform + "/";
new File(imagesLocation).mkdirs(); // Insure directory is there
String filename = imagesLocation + testName + ".jpg";
try {
Thread.sleep(500);
WebDriver augmentedDriver = new Augmenter().augment(driver);
File scrFile = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(filename), true);
} catch (Exception e) {
System.out.println("Error capturing screen shot of " + testName + " test failure.");
// remove old pic to prevent wrong assumptions
File f = new File(filename);
f.delete(); // don't really care if this doesn't succeed, but would like it to.
}
}
这种方法适用于Android,但最近它完全杀死了运行测试,但这可能与它试图获取快照的设备有关.在保存文件之前,图像会出现空白或损坏.
任何人都知道如何使用appium在android上运行图像/屏幕捕获?也许是UIAutomator的东西?