2
votes

I'm testing a hybrid app built with Ionic (Cordova, AngularJS) using Appium C# bindings. Having moderate success interacting with elements that have an id property. It would make my life a lot easier to be able to use css selectors with FindElementByCssSelector, however you cannot use that with the NATIVE_APP context.

[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

So I need to switch the context to WEBVIEW to be able to use css selectors. The app is built with WebView.setWebContentsDebuggingEnabled(true). I have verified the available contexts as follows:

ReadOnlyCollection<string> contexts = device.Contexts;

Contexts are NATIVE_APP and WEBVIEW_com.blah.myapp. I switch to webview thus:

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

It sets fine, but Chromedriver eventually fails with chrome not reachable. Here's the logging info. I have no idea where to go next with the chromdriver error.

[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))

Edit: Using Appium 1.7.2-beta5 (had same failure on previous version) Android 7.0 and 6.0, real device and emulator as well

1

1 Answers

2
votes

That is an ongoing issue with Appium & Chromedriver, there is no exact solution for every case, so you have to try different ones:

  1. Try the latest beta - 1.8.0-beta available:
npm uninstall -g appium && npm install -g appium@beta
  1. Try different version of chromedriver using these instructions:

    • Download and extract chromedriver
    • Start appium server with path to downloaded chromedriver
    appium --chromedriver-executable /path/to/my/chromedriver
    
    • Run your test and see if it works

You also may track progress on this issue specific for 1.7.2-beta and Android 6.