我无法截屏失败。早些时候,我的真实iOS设备上的一切都还可以,但现在 - Appium崩溃了,屏幕截图没有拍摄,我无法弄清楚发生了什么。
Appium日志:link here
Java代码:
public void takeScreenShotOnFailure(ITestResult testResult, String name) throws IOException {
if (testResult.getStatus() == ITestResult.FAILURE) {
File scrFile = dr.getScreenshotAs(OutputType.FILE);
Date date = new Date();
SimpleDateFormat home = new SimpleDateFormat("dd.MM hh:mm:ss");
String homedate = home.format(date);
FileUtils.copyFile(scrFile, new File("test-output/screenshots/" + name + ".jpg"));
}
}
有什么想法吗?
答案 0 :(得分:1)
试试这段代码:
private Camera.Size getBestPreviewSize(Camera.Parameters parameters, int width, int height) {
Camera.Size result = null;
double ratio = width / height;
double w = 0, h = 0;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
w = size.width;
h = size.height;
if (w / h == ratio) {
if (result != null) {
if (w > result.width) {
result = size;
}
} else {
result = size;
}
}
}
return (result);
}
答案 1 :(得分:0)
File file = m_driver.getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(file, new File(screenshotName + "ScreenShot.jpg"));
System.out.println(screenshotName + "ScreenShot.jpg generated\n");
} catch (IOException e) {
e.printStackTrace();
}
这就是我使用IOSDriver m_driver生成屏幕截图的方法。我在Mac上使用它。从您的日志中,我建议您在尝试截屏时确保IOSDriver仍然活着。