Appium 切换 webview 模式,遇到 chromedriver 报错的问题

兰溪 · 2014年09月28日 · 最后由 taurusbb 回复于 2017年03月14日 · 3104 次阅读

被测 app 是混合型 app,某个功能需要切换 webview。代码如下:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName","Android");
capabilities.setCapability("deviceName","4d00c2ccb0dd6063");

capabilities.setCapability("automationName","Android"); 
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.4");
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {

  System.out.println(contextName); // 用于返回被测app是NATIVE_APP还是WEBVIEW,如果两者都有就是混合型App
  if (contextName.contains("WEBVIEW")) 
      driver.context(contextName);

}

运行到
driver.context(contextName);
时,appium 报错,错误日志如下:

error: Chromedriver create session did not work. Status was 200 and body was{"sessionId":"276ad6edf24e1798bd79b4e5aabfc1bc","status":13,"value":{"message":"unknown error: Chrome version must be >= 33.0.1750.0\n  (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64)"}}
info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command. (Original error: Did not get session redirect from Chromedriver)","origValue":"Did not get session redirect from Chromedriver"},"sessionId":"f8d68152-f368-47a4-9a3d-8c66af8b84e4"}

请教问题的原因和解决办法。。无限感激!!!

共收到 25 条回复 时间 点赞

日志里不是写的很清楚么? Chrome version must be >= 33.0.1750.0\n (Driver info: chromedriver=2.10.267521,

兰溪 #24 · 2014年09月28日 Author

#1 楼 @lihuazhang 依据此日志,去给手机和 pc 安装最新版本的 chrome,结果还是一样。

#2 楼 @lacylee200 出错日志一样?

兰溪 #22 · 2014年09月28日 Author

#3 楼 @lihuazhang 是的,完全一样

兰溪 #19 · 2014年10月17日 Author

#6 楼 @sanlengjingvv 首先感谢你的帮助。我英文不太好,你发的帖子里内容,好像是要等官方来去解决的意思?

遇到和 lz 一样的问题,请问解决了吗??

#7 楼 @lacylee200 @abyssalknight
10 楼给了个他修改过的 chromedriver,替换掉\Appium\node_modules\appium\build\chromedriver\windows 下的 chromedriver。

我的 genymotion 有这个问题(貌似升级前是好的,但没 2.2 镜像了),sdk 自带的模拟器没问题

兰溪 #10 · 2014年10月26日 Author

#9 楼 @sanlengjingvv 你是如何解决这个问题的?换一台手机 or 用 sdk 模拟器?

#10 楼 @lacylee200 6 楼链接里的 10 楼,有个 chromedriver 下载地址,下好替换\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe

Latest Release: ChromeDriver 2.13

Fixed bugs:
Chromedriver times out waiting for Tracing.end command to respond
GoBack command times out on all platforms
ChromeDriver port server fails to reserve port
Commands goBack and goForward have race condition.
chromedriver fails with "Chrome version must be >= 31.0.1650.59" on Android 4.4.3 webviews
silence chrome logging by default on windows
ChromeDriver fails to close DevTools UI before executing commands

chromedriver 最新的 2.13 已经解决 fix 这个问题,直接到官网下载一个 2.13 的 chromedriver。

在官方下了 2.13 也报错同样的错误。

chromedriver 的路径我搞错了。
现在解决了~~呵呵~ 谢谢~

兰溪 #15 · 2015年01月08日 Author

#12 楼 @qddegtya 谢谢,试试!

兰溪 #16 · 2015年01月08日 Author

当下好新的 chromedriver,一切都准备好之后,run。。。 然后又郁闷了。。。getContextHandles() 方法只返回 “NATIVE_APP”,没有办法 driver.context("WEBVIEW") 进行验证啊郁闷啊

@lacylee200 我也有同样的问题。在真机上不显示 webview,在 emulator 上正常。不知道为什么。http://testerhome.com/topics/1788

我下载最新的 chromedriver 2.15 版本,还是报这个错,为啥,请教~~

#14 楼 @jinjun0620 我更新 chromedriver 到 2.13 版本,还是有问题啊
Chromedriver create session did not work. Status was 200 and body was {"sessionId":"817d4d9773d524ef6c0c402d807ec5dd","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.13.307650 (feffe1dd547ee7b5c16d38784cd0cd679dfd7850),platform=Mac OS X 10.9.2 x86_64)"}}
Debug:[36minfo[39m: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command. (Original error: Did not get session redirect from Chromedriver)","origValue":"Did not get session redirect from Chromedriver"},"sessionId":null}
Debug:[36minfo[39m: [37m<-- POST /wd/hub/session/51f1d079-0ffd-4b01-ae57-caac439c41d6/context [39m[31m500[39m[90m 61264.093 ms - 246[39m [90m[39m

#17 楼 @jinjun0620 咋搞错路径了?

#9 楼 @sanlengjingvv 有 mac 版的 chromedriver 马?能给提供下嘛

我今天也遇到了这个问题,已解决。
Appium 模式:现公布解决方法,首先可能需要更新 chromedriver 到最新版本(或者使用 appium1.4.0 自带 2.15.322448),在模拟器或手机端安装 chrome,版本号大于 33 即可(我使用的是 43.0.2357.93),做好以上准备工作后在任务管理器中干掉 chromedriver 进程。
运行成功后的 Appium 关键日志如下:

> info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.**.**
> info: [debug] Connecting to chrome-backed webview
> info: Set chromedriver binary as: d:\Program Files\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
> info: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))
> info: Successfully cleaned up old chromedrivers
> info: Spawning chromedriver with: d:\Program Files\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe --url-base=wd/hub --port=9515
> info: [CHROMEDRIVER STDOUT] Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515
> Only local connections are allowed.
> info: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
> info: Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Windows NT","version":"6.1 SP1"}}}
> info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.**.**","androidUseRunningApp":true,"androidDeviceSerial":"192.168.180.101:5555"}}}
> info: Got response with status 200: {"sessionId":"281726e22ffb4337f02a6649aff41056","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSelect...
> info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"0319316c-5f0e-4b90-952b-689313a56cbf"}
> info: <-- POST /wd/hub/session/0319316c-5f0e-4b90-952b-689313a56cbf/context 200 6008.816 ms - 76 {"status":0,"value":null,"sessionId":"0319316c-5f0e-4b90-952b-689313a56cbf"}
> info: --> POST /wd/hub/session/0319316c-5f0e-4b90-952b-689313a56cbf/element {"using":"id","value":"username"}
> info: Proxying [POST /wd/hub/session/0319316c-5f0e-4b90-952b-689313a56cbf/element] to [POST http://127.0.0.1:9515/wd/hub/session/281726e22ffb4337f02a6649aff41056/element] with body: {"using":"id","value":"username"}
> info: Got response with status 200: 

#23 楼 @adfghzhang
在 Appium 日志中,

Only local connections are allowed.
info: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
info: Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Windows NT","version":"6.1 SP1"}}}
info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com..","androidUseRunningApp":true,"androidDeviceSerial":"192.168.180.101:5555"}}}
之后就一直到 Appium 超时没有反应,有什么解决方法吗?是什么原因导致的?
超时设置改为 120 秒也没有用

不稳定,经常出现这个问题,大概有 90% 的概率。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册