Appium (v1.4.16.1),第二次尝试切换到 WebView 失败

Appium (v1.4.16.1), Switch to WebView fails when i try a second time

Appium (v1.4.16.1),第二次切换webview时,切换webview失败。有什么我应该考虑的吗?

请参考以下在 Android-

上使用 Appium 的用例
  1. 启动 Android 设备 > 执行一些操作
  2. 切换上下文 = WebView_1 > 执行一些操作
  3. 切换上下文 = Native_App
  4. 切换上下文 = WebView_1 > 执行一些操作

Step#2和Step#4相同WebView_1,只是内容不同。说:步骤#2 打开了 html-1,步骤#4 打开了 html-2.

问题:我无法在步骤#4 中切换上下文。

.... below are some logs of the error

info: [debug] Available contexts: NATIVE_APP,WEBVIEW_1 info: [debug] Connecting to chrome-backed webview info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command. (Original error: We already have a chromedriver instance running)","origValue":"We already have a chromedriver instance running"},"sessionId":"38904ff5-928a-4dc0-ac8a-c7bc5f6504e4"}

当我创建 Selenium WebDriver / RemoteWebDriver 的第二个实例并尝试连接到 Appium 服务器而没有准确关闭第一个实例时,我遇到了完全相同的错误。 Appium在这方面有点小气。

切换到 webview 然后再切换到 native_app 在 appium 中引起广泛的问题,我遇到了同样的问题并且在研究之后我发现切换到 webview 时,chromedriver 有时会变得没有响应并且 appium 等待 chromedriver 直到为 appium 定义的超时,因此会出现这些问题,如何解决这个问题: 创建一个线程来监控chromedriver,当它挂起时,重启chromedriver。

现成的解决方案:从 https://github.com/mi2pankaj/chromeDriverHandler 下载 chromedriverhandler.jar,添加到您的项目中,

在 beforeTest/beforeClass 或测试开始时使用它: ChromedriverHandler.chromeDriverHandlerThread().开始();

在 afterTest/afterClass 或测试结束时使用它: ChromedriverHandler.chromeDriverHandlerThread().stop();

注意:您可能需要将这些添加到您的项目中:apache 的 httpclient-4.3.1.jar、httpcore-4.3.jar 和 json 简单的 jar:json-20080701.jar

希望对您有所帮助。