java - 使用 AppiumDriver 截屏时出现浏览器无法访问的异常
问题描述
我们使用 Perfecto 来测试我们的移动应用程序。我们的自动化代码在我们尝试捕获移动屏幕屏幕截图的步骤中生成异常。
我们尝试更改 jar 的版本。最初我们有 Selenium 远程驱动程序 2.48.2。我们将其更改为 2.53.1 并更新了所有其他依赖的 jar。在 2.48.2 中,我们继续得到 Browser unreachable 异常,现在在 2.53.1 中,我们正在超时。我在 2.48.2 版中包含了异常详细信息(带有示例代码段)。2.53.1 的例外情况有一些凭据详细信息,我不确定如何共享这些信息。
异常详情
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
System info: host: 'WDAAS6302-E1087', ip: '10.86.78.84', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_172'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:206)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:325)
at reusable.ReusableFuncs.capture(ReusableFuncs.java:167)
at automationFramework.Trial.main(Trial.java:160)
Caused by: java.lang.NullPointerException
at org.openqa.selenium.remote.ErrorCodes.toStatus(ErrorCodes.java:256)
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:124)
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:42)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.decode(JsonHttpResponseCodec.java:78)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:145)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:67)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:620)
... 5 more
例外是在步骤 - File source = ts.getScreenshotAs(OutputType.FILE);
移动自动化对我们来说相当新,我们发现很难解决这个问题。
public synchronized String capture(AppiumDriver<MobileElement> driver,String screenShotName) throws IOException
{
TakesScreenshot ts = (TakesScreenshot)driver;
String dest = System.getProperty("user.dir") +"\\ErrorScreenshots\\"+screenShotName+new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date())+".png";
System.out.println("destination is "+ dest);
File source = ts.getScreenshotAs(OutputType.FILE);
File destination = new File(dest);
FileUtils.copyFile(source, destination);
destination = null;
dest = resize(dest);
destination = new File(dest);
String encodedfile = null;
try {
FileInputStream fileInputStreamReader = new
FileInputStream(destination);
byte[] bytes = new byte[(int)destination.length()];
fileInputStreamReader.read(bytes);
encodedfile = Base64.getEncoder().encodeToString(bytes);
System.out.println(encodedfile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "data:image/png;base64,"+ encodedfile;
}
解决方案
我想你可以试试Experitest SeeTest
你的移动自动化项目它有内置的报告机制,可以截图。它支持AppiumDriver
你的情况。您可以查看Experitest 文档
String screenshotPath = client.capture("CaptureScreenshot")
ScreenshotPath
将保存捕获的屏幕截图的路径
推荐阅读
- c# - 在安装文件中包含 TeamViewer.exe 文件
- vba - 如果单元格在任何工作表中包含字符串,则 Excel VBA 宏设置左对齐
- r - Purrr 根据包含字符向量的未嵌套变量过滤嵌套数据
- django - 使用外键引用保存 Django 表单
- neo4j - Neo4j 缺少一些程序
- c# - 值不能为空(绘制数据表)
- javascript - 如何过滤道具以使用 ReactJS 进行渲染?
- ruby-on-rails - 在为 Rails 项目的阿拉伯语 lang 文件解析第 ... 行的块映射时没有找到预期的密钥
- python - 在python中输入变量
- c# - 使用 C# 在什么情况下在 String 或 Char 上使用 ToString() 时需要提供 CultureInfo IFormatProvider?