appium/python-client

Proxy error happens when we run test in Chrome Driver following W3C protocol

tangzhoutz opened this issue · 9 comments

in commit(add appium prefix in create session and fix find_elements for W3C (#196)),
The problem is as follows: I am from China, China's WeChat is very hot, you should know. I used the 0.26 version before. In the WeChat test, when I test the public number, I need to switch to webview first, then switch to window_handles, the code is normal; last Friday I upgraded to version 0.28 and found an error in the driver.window_handles code. : "/session/$sessionId/window/handles" unkown command.
The following steps to deal with the problem

  1. I rolled back to version 0.26 and found that the command used for the log here is: "/session/$sessionId/window_handles"
    2, I further compare the update code twice, this time update the code _make_w3c_caps () method 73,74 lines, plus appium_prefix, will cause the proxy request response does not have a status field, resulting in the start_session () method The value of self.w3c is true;
  2. When I execute driver.window_handles, the source code is based on self.w3c and will execute self.execute(Command.W3C_GET_WINDOW_HANDLES)['value']. ​​However, this command format reports an error on the app: unkown command(/session/$sessionId /window/handles).
    4, I tried to comment out the code to add appium_prefix, will return the status field normally, and correctly execute self.execute(Command.GET_WINDOW_HANDLES)['value'], /session/$sessionId/window_handles.
    5, I don't know if the appium_prefix related code will be commented out, it will affect other functions, I hope to fix it as soon as possible.

It is because the server side doesn't support W3C spec windows handler even the client works for W3C protocol, I assume.

  • /session/$sessionId/window_handles => MJSON protocol
  • /session/$sessionId/window/handles => W3C protocol

  1. Could you attach your server logs? We can see many data from the log
  2. What version of Appium do you use? If you use Appium1.8.0+, the handler probably works with W3C spec agains Android/iOS.
  3. You can use forceMjsonwp=True in your capability. The capability is mainly for users how happens W3C protocol. I believe you put the capability, your Appium server work following MJSON protocol.
    _FORCE_MJSONWP = 'forceMjsonwp'

appium-server-logs.txt
1, this is my service log, the attachment has been uploaded.
2. I am using Appium1.8.1.
3.forceMjsonwp=True this setting is used, the code can run normally and use MJSON protocol

Thanks!

Does it happen only WebView context?

[debug] �[35m[AndroidDriver]�[39m Found webviews: ["WEBVIEW_com.tencent.mm","WEBVIEW_com.tencent.mm:tools"]
[debug] �[35m[AndroidDriver]�[39m Available contexts: ["NATIVE_APP","WEBVIEW_com.tencent.mm","WEBVIEW_com.tencent.mm:tools"]
[debug] �[35m[AndroidDriver]�[39m Connecting to chrome-backed webview context 'WEBVIEW_com.tencent.mm:tools'
[debug] �[35m[AndroidDriver]�[39m A port was not given, using random port: 8000
[debug] �[35m[Chromedriver]�[39m Changed state to 'starting'
[info] �[35m[Chromedriver]�[39m Set chromedriver binary as: E:\pyworkspace\python1\driver\chromedriver.exe
[debug] �[35m[Chromedriver]�[39m 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))[warn] �[35m[Chromedriver]�[39m No old chromedrivers seemed to exist
[debug] �[35m[Chromedriver]�[39m Cleaning any old adb forwarded port socket connections
[debug] �[35m[ADB]�[39m List forwarding ports
[debug] �[35m[ADB]�[39m Running 'F:\Android\android-sdk\platform-tools\adb.exe -P 5037 -s SQRNW17901001536 forward --list'
[info] �[35m[Chromedriver]�[39m Spawning chromedriver with: E:\pyworkspace\python1\driver\chromedriver.exe --url-base=wd/hub --port=8000 --adb-port=5037 --verbose[debug] �[35m[Chromedriver]�[39m Chromedriver version: '2.29.461591'
[debug] �[35m[JSONWP Proxy]�[39m Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body[debug] �[35m[JSONWP Proxy]�[39m Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0.17134\"}}}"
[debug] �[35m[JSONWP Proxy]�[39m Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"SQRNW17901001536"}}}[debug] �[35m[Chromedriver]�[39m Webview version: 'Chrome/57.0.2987.132'[debug] �[35m[JSONWP Proxy]�[39m Got response with status 200: {"sessionId":"836004d292cb4ec712e07668fb911e21","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.29.461591 (62ebf098771772160f391d75e589dc567915b233)"},"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":true,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"pageLoadStrategy":"normal","platform":"ANDROID","rotatable":false,"takesHeapSnapshot":true,"takesScreenshot":true,"unexpectedAlertBehaviour":"","version":"57.0.2987.132","webStorageEnabled":true}}
[debug] �[35m[Chromedriver]�[39m Changed state to 'online'
[debug] �[35m[W3C]�[39m Responding to client with driver.setContext() result: null
[info] �[35m[HTTP]�[39m �[37m<-- POST /wd/hub/session/e5a41156-36d4-47e0-aa02-9147f4a173c2/context �[39m�[32m200�[39m �[90m3386 ms - 14�[39m
[info] �[35m[HTTP]�[39m �[90m�[39m[info] �[35m[HTTP]�[39m �[37m-->�[39m �[37mGET�[39m �[37m/wd/hub/session/e5a41156-36d4-47e0-aa02-9147f4a173c2/window/handles�[39m
[info] �[35m[HTTP]�[39m �[90m{}�[39m
[info] �[35m[W3C]�[39m Driver proxy active, passing request on via HTTP proxy
[debug] �[35m[JSONWP Proxy]�[39m Proxying [GET /wd/hub/session/e5a41156-36d4-47e0-aa02-9147f4a173c2/window/handles] to [GET http://127.0.0.1:8000/wd/hub/session/836004d292cb4ec712e07668fb911e21/window/handles] with body: {}
[warn] �[35m[JSONWP Proxy]�[39m Got unexpected response: unknown command: session/836004d292cb4ec712e07668fb911e21/window/handles
[error] �[35m[W3C]�[39m Encountered internal error running command: Error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: 404 - "unknown command: session/836004d292cb4ec712e07668fb911e21/window/handles"
[error] �[35m[W3C]�[39m     at doJwpProxy$ (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:456:13)
[error] �[35m[W3C]�[39m     at tryCatch (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
[error] �[35m[W3C]�[39m     at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
[error] �[35m[W3C]�[39m     at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
[error] �[35m[W3C]�[39m     at GeneratorFunctionPrototype.invoke (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[error] �[35m[W3C]�[39m     at <anonymous>
[info] �[35m[HTTP]�[39m �[37m<-- GET /wd/hub/session/e5a41156-36d4-47e0-aa02-9147f4a173c2/window/handles �[39m�[31m500�[39m �[90m42 ms - 1661�[39m
[info] �[35m[HTTP]�[39m �[90m�[39m

According to http://chromedriver.chromium.org/downloads , chrome driver supports W3C spec over 2.37. You use 2.29.461591. Could you try the new one?
@tangzhoutz

Yes, it only happens in the WebView context.
Ok, I try

Thanks!

  1. I tried it.
      However, my webview is version 57. I can't use chrome driver higher than 2.29 or higher.
    2, so the reason for this problem is that my chrome driver version is too low, does not support W3C. And the webview version is too low, does not support the high version of the chrome driver?

ah... I see. Thanks for it!

Using forceMjsonwp is workaround in the case, so far.

I used the latest mobile phone to test the 2.39 version of the driver. There is no such problem. Thanks!

Perfect 👍

Let me add a warning message and suggestions in somewhere for the case.
(maybe, appium-chromedriver?)

That's great, thank you very much for helping me answer the question.