![](/img/trans.png)
[英]Appium Android - take screenshot returns "Illegal base64 character a"
[英]Capturing Android screenshot with appium
我目前正在使用iOS和Java捕获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有什么用?
您可以使用以下方法:
public void screenshot(String path_screenshot) throws IOException{
File srcFile=driver.getScreenshotAs(OutputType.FILE);
String filename=UUID.randomUUID().toString();
File targetFile=new File(path_screenshot + filename +".jpg");
FileUtils.copyFile(srcFile,targetFile);
}
这对我来说可以。
我碰巧通过Google搜索找到了几乎相同的问题-Android模拟器中的Appium屏幕截图空白。 我正在像您在上面描述的那样使用“本机”方法,以及ATU框架中的方法。
WebElement appArea = wd.findElementByXPath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]");
ATUReports.add("Main Screen Area Screenshot", LogAs.INFO, new CaptureScreen(appArea));
并且都恢复为空白/透明。 好消息是,空白/透明图像的尺寸恰好是我要捕获的尺寸-避免出现状态栏,因为日期差异会导致图像比较出错。 就是说,如果没有实际可见的像素(用于最终将对象区域抓图与经过验证的基准图像进行匹配),它的使用就很少。
我尝试将上下文设置为“ NATIVE_APP”,似乎没有任何帮助。 一言以蔽之,我很烦。 如果您在此方面取得了任何进展,我将很乐意阅读/了解您的工作方式。 也许下一步就是去Appium Google Group。
编辑:我发现我的核心问题-使用HAXM加速会导致黑屏。 请注意,如果在测试功能中设置的基本设备配置文件是通过选择“主机GPU”定义的,这也会影响物理设备上的测试运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.