java - Appium getScreenshotAs() 抛出 java.lang.IllegalStateException:无法压缩回收的位图(Samsung Galaxy A3 2017)
问题描述
public static BufferedImage createScreenshotOfMiddleOfTheElement(final MobileElement element) throws Exception {
final File screenshotFile = element.getScreenshotAs(OutputType.FILE);
final BufferedImage screenshot = ImageIO.read(screenshotFile);
final int width = screenshot.getWidth() / 5;
final int height = screenshot.getHeight() / 5;
final int x = width * 2;
final int y = height * 2;
return screenshot.getSubimage(x, y, width, height);
}
在上述方法的第一行中,当尝试对该元素进行截图时,Appium 将抛出:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: java.lang.IllegalStateException: Can't compress a recycled bitmap
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'xyz-pc', ip: '10.100.0.244', os.name: 'Linux', os.arch: 'amd64', os.version: '5.3.7-arch1-1-ARCH', java.version: '1.8.0_222'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appWaitPackage: x.y.z, automationName: UiAutomator2, databaseEnabled: false, desired: {appWaitPackage: x.y.z, automationName: UiAutomator2, deviceName: Android Device, platformName: android}, deviceApiLevel: 26, deviceManufacturer: samsung, deviceModel: SM-A320FL, deviceName: 5203e9e65af0c3a9, deviceScreenDensity: 320, deviceScreenSize: 720x1280, deviceUDID: 5203e9e65af0c3a9, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, pixelRatio: 2, platform: LINUX, platformName: Android, platformVersion: 8.0.0, statBarHeight: 48, takesScreenshot: true, viewportRect: {height: 1232, left: 0, top: 48, width: 720}, warnings: {}, webStorageEnabled: false}
Session ID: fd18b3e6-22af-4e34-945d-5797ddd00a6a
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
at org.openqa.selenium.remote.RemoteWebElement.getScreenshotAs(RemoteWebElement.java:392)
at common.ImageUtils.createScreenshotOfMiddleOfTheElement(ImageUtils.java:19)
到目前为止,代码都能正确执行。可疑的是 - 它只在三星 Galaxy A3 (2017) 上中断。我该如何解决?
解决方案
推荐阅读
- rascal - Rascal:在 Windows 命令行上找不到 JDK
- amazon-web-services - AWS Amplify 应用程序未在托管子域上执行 CloudFront 重定向
- python - 通过 aws lambda 下载文件
- sql - 如何将空白值传递给日期参数?
- sql - 查询中具有不同条件的 3 列
- regex - 彭博批量数据正则表达式解析
- r - 将 ggplot 与非数字数据一起使用
- python - 在一个函数中并行运行多个数据帧
- javascript - 如何在 JavaScript 中从数组中渲染图像
- angular - Angular 8 中的 mat-table 排序工作方式不同,大写、小写以及数字和空值的排序方式不同