无法为WEBVIEW设置上下文

时间:2018-01-17 22:24:19

标签: android appium

我正在使用Appium C#绑定测试使用Ionic(Cordova,AngularJS)构建的混合应用程序。适度成功与具有id属性的元素交互。这将使我的生活更容易使用FindElementByCssSelector的css选择器,但是你不能在NATIVE_APP上下文中使用它。

[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["css selector", "button[ng-click='something']","0ab74e91-afc4-4f90-8702-f2be13f235c5"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator

所以我需要将上下文切换到WEBVIEW才能使用css选择器。该应用程序使用WebView.setWebContentsDebuggingEnabled(true)构建。我已经验证了可用的上下文如下:

ReadOnlyCollection<string> contexts = device.Contexts;

上下文为NATIVE_APPWEBVIEW_com.blah.myapp。我转而使用webview:

device.Context = "WEBVIEW_com.blah.myapp";

它很好,但Chromedriver最终以chrome not reachable失败。这是日志信息。我不知道下一步会出现chromdriver错误。

[debug] [MJSONWP] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_com.blah.myapp"]
[HTTP] <-- GET /wd/hub/session/ad3e9aee-d794-43d9-9896-497846dec4f4/contexts 200 230 ms - 119
[HTTP] --> POST /wd/hub/session/ad3e9aee-d794-43d9-9896-497846dec4f4/context {"name":"WEBVIEW_com.blah.myapp"}
[debug] [MJSONWP] Calling AppiumDriver.setContext() with args: ["WEBVIEW_com.blah.myapp","ad3e9aee-d794-43d9-9896-497846dec4f4"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\xxxxx\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","shell","cat","/proc/net/unix"]
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_com.blah.myapp"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_com.blah.myapp"]
[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_com.blah.myapp'
[debug] [AndroidDriver] A port was not given, using random port: 8000
[debug] [Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: C:\Users\xxxxx\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
[debug] [Chromedriver] Killing any old chromedrivers, running: FOR /F "usebackqtokens=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
[debug] [Chromedriver] Cleaning any old adb forwarded port socket connections
[debug] [ADB] List forwarding ports
[debug] [ADB] Running 'C:\Users\xxxxx\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","forward","--list"]
[debug] [ADB] Removing forwarded port socket connection: 12980
[debug] [ADB] Running 'C:\Users\xxxxx\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","0123456789ABCDEF","forward","--remove","tcp:12980"]
[Chromedriver] Spawning chromedriver with: C:\Users\xxxxx\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=8000 --adb-port=5037 --verbose
[debug] [Chromedriver] Chromedriver version: '2.34.522940'
[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.blah.myapp","androidUseRunningApp":true,"androidDeviceSerial":"0123456789ABCDEF"}}}
[HTTP] <-- POST /wd/hub/session/ad3e9aee-d794-43d9-9896-497846dec4f4/context - - ms - -
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"bbe4bf5c4a6bdd020f27e07624258589","status":100,"value":{"message":"chrome not reachable\n  (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
[Chromedriver] Error: Failed to start Chromedriver session: An error occurred (Original error: chrome not reachable  (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.1.7601 SP1 x86_64))

编辑: 使用Appium 1.7.2-beta5(在以前的版本中出现相同的故障) Android 7.0和6.0,真实设备和模拟器

1 个答案:

答案 0 :(得分:2)

Appium & Chromedriver这是一个持续存在的问题,对于每个案例都没有确切的解决方案,所以你必须尝试不同的解决方案:

  1. 试用最新的测试版 - 1.8.0-beta
  2. npm uninstall -g appium && npm install -g appium@beta
    
    1. 使用这些instructions尝试不同版本的chromedriver:

      • 下载并解压缩chromedriver
      • 启动appium服务器,并提供下载chromedriver的路径
      appium --chromedriver-executable /path/to/my/chromedriver
      
      • 运行测试并查看是否有效
    2. 您还可以跟踪针对1.7.2-beta和Android 6的this issue的进度。