测试背景:自动化测试微信公众号网页

问题描述:
1.Appium(版本 1.6.2)转换 webview context 失败。报错 chrome not reachable
2.测试使用安卓真机,android version 5.1.1
3.在转换的过程中,我留意到真机已经成功进入网页并能加载所有元素,但是就是不能对里面的元素进行操作。chrome browser is invoking but not communicating with the opened window. session 过了大概一分钟才正式关闭。

尝试解决方法:

google 有人说可能是 chromedriver 没有绕过代理设置。通过设置 Internet Properties->connections->LAN settings, set 'Bypass proxy server for local addresses'可以解决这个问题。--------------------我的情况实测不起作用。
google 说有时候引起这个问题是由于 chromedriver 对切换 webview 请求没有及时响应,而 appium 一直在等待 chromedriver 的进一步动作导致超时。所以要解决这个问题的方法就是创建一个线程来监控 chromedriver,当 chromedriver 停止运行,唤醒它。

下面是我的 appium 日志

[HTTP] --> GET /wd/hub/session/3fd60116-5418-4bdf-8c4e-e5f6627b837a/contexts {}
[debug] [MJSONWP] Calling AppiumDriver.getContexts() with args: ["3fd60116-5418-4bdf-8c4e-e5f6627b837a"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'D:\software_home\Android_sdk\adt-bundle\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","cat","/proc/net/unix"]
[debug] [AndroidDriver] WEBVIEW_19192 mapped to pid 19192
[debug] [AndroidDriver] Getting process name for webview
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'D:\software_home\Android_sdk\adt-bundle\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","ps"]
[debug] [AndroidDriver] Parsed pid: 19192 pkg: com.tencent.mm:tools!
[debug] [AndroidDriver] from: u0_a81,19192,1942,1544284,100912,ffffffff,00000000,S,com.tencent.mm:tools
[debug] [AndroidDriver] returning process name: com.tencent.mm:tools
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_com.tencent.mm:tools"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:tools"]
[debug] [MJSONWP] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_com.tencent.mm:tools"]
[HTTP] <-- GET /wd/hub/session/3fd60116-5418-4bdf-8c4e-e5f6627b837a/contexts 200 1075 ms - 117
[HTTP] --> POST /wd/hub/session/3fd60116-5418-4bdf-8c4e-e5f6627b837a/context {"name":"WEBVIEW_com.tencent.mm:tools"}
[debug] [MJSONWP] Calling AppiumDriver.setContext() with args: ["WEBVIEW_com.tencent.mm:tools","3fd60116-5418-4bdf-8c4e-e5f6627b837a"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'D:\software_home\Android_sdk\adt-bundle\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","cat","/proc/net/unix"]
[debug] [AndroidDriver] WEBVIEW_19192 mapped to pid 19192
[debug] [AndroidDriver] Getting process name for webview
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'D:\software_home\Android_sdk\adt-bundle\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","ps"]
[debug] [AndroidDriver] Parsed pid: 19192 pkg: com.tencent.mm:tools!
[debug] [AndroidDriver] from: u0_a81,19192,1942,1560304,110312,ffffffff,00000000,S,com.tencent.mm:tools
[debug] [AndroidDriver] returning process name: com.tencent.mm:tools
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_com.tencent.mm:tools"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm:tools"]
[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.tencent.mm:tools'
[debug] [AndroidDriver] A port was not given, using random port: 8000
[debug] [Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\appium-chromedriver\2.9.4\appium-chromedriver\chromedriver\win\chromedriver.exe
[Chromedriver] Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"8000 ") do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe) do (IF NOT %b=="" TASKKILL /F /PID %a))
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\appium-chromedriver\2.9.4\appium-chromedriver\chromedriver\win\chromedriver.exe --
url-base=wd/hub --port=8000 --adb-port=5037
[Chromedriver] [STDOUT] Starting ChromeDriver 2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed) on port 8000
Only local connections are allowed.
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"6.
1.7601 SP1\"}}}"
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningA
pp":true,"androidDeviceSerial":"0123456789ABCDEF"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"f53c787a58f62c87150b8fa107be307d","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.25.426923 (03
90b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningA
pp":true,"androidDeviceSerial":"0123456789ABCDEF"}}}
[HTTP] --> DELETE /wd/hub/session/3fd60116-5418-4bdf-8c4e-e5f6627b837a {}
[debug] [MJSONWP] Calling AppiumDriver.deleteSession() with args: ["3fd60116-5418-4bdf-8c4e-e5f6627b837a"]
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Resetting IME to com.android.inputmethod.latin/.LatinIME
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'D:\software_home\Android_sdk\adt-bundle\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","ime","set","com.and
roid.inputmethod.latin/.LatinIME"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'D:\software_home\Android_sdk\adt-bundle\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","am","force-stop","com.tencent.mm"]
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'D:\software_home\Android_sdk\adt-bundle\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","input","keyevent",3]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state 'stopping'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Closed client connection
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: current=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: 0
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Test results for WatcherResultPrinter=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Time: 109.533
[debug] [AndroidBootstrap] [UIAUTO STDOUT] OK (1 test)
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: -1
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'D:\software_home\Android_sdk\adt-bundle\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'D:\software_home\Android_sdk\adt-bundle\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","am","force-stop","io.appium.unlock"]
[debug] [Logcat] Stopping logcat capture
[debug] [AndroidDriver] Not cleaning generated files. Add clearSystemFiles capability if wanted.
[Appium] Removing session 3fd60116-5418-4bdf-8c4e-e5f6627b837a from our master session list
[debug] [MJSONWP] Received response: null
[debug] [MJSONWP] But deleting session, so not returning
[debug] [MJSONWP] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/3fd60116-5418-4bdf-8c4e-e5f6627b837a 200 6021 ms - 76
[HTTP] <-- POST /wd/hub/session/3fd60116-5418-4bdf-8c4e-e5f6627b837a/context - - ms - -
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"f449b3df3f3d38d7f9bd99e89b140692","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"0123456789ABCDEF"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"aead2b91c6f5e51df6f9595492248f1e","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"0123456789ABCDEF"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"e3d31d035b41bfb4f7471edb7f79b137","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
[Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[debug] [Chromedriver] Changed state to 'stopped'
[Chromedriver] Error: chrome not reachable
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\appium-chromedriver\2.9.4\appium-chromedriver\build\lib\chromedriver.js:393:27)
at tryCatch (C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\babel-runtime\5.8.24\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\babel-runtime\5.8.24\babel-runtime\regenerator\runtime.js:136:37)
Error: chrome not reachable
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\appium-chromedriver\2.9.4\appium-chromedriver\build\lib\chromedriver.js:393:27)
at tryCatch (C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\babel-runtime\5.8.24\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\babel-runtime\5.8.24\babel-runtime\regenerator\runtime.js:136:37)
[MJSONWP] Encountered internal error running command: Error: chrome not reachable
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\appium-chromedriver\2.9.4\appium-chromedriver\build\lib\chromedriver.js:393:27)
at tryCatch (C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\babel-runtime\5.8.24\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Users\Administrator\AppData\Roaming\npm\node_modules.appium_npminstall\babel-runtime\5.8.24\babel-runtime\regenerator\runtime.js:136:37)

下面是我的用例报告

1) should navigate to the shopping mall homepage
timeout of 100000ms exceeded. Ensure the done() callback is being called in this test.
running
Error: timeout of 100000ms exceeded. Ensure the done() callback is being called in this test.
at Timeout.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules.wdio-mocha-framework_npminstall\mocha\2.5.3\mocha\lib\runnable.js:226:19)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)

如果有遇到同样问题的朋友,还请告知详细解决方法。thanks in advance。


↙↙↙阅读原文可查看相关链接,并与作者交流