【发布时间】:2014-05-31 22:23:20
【问题描述】:
我目前正在使用 java 和 junit 在 iOS 上为 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 相关?
【问题讨论】:
-
你试过没有'true'参数吗:FileUtils.copyFile(scrFile, new File(filename), true);并且还使用最新的appium?我正在使用非常相似的代码,对我来说效果很好