Appium Appium1.80 新增自动选择手机正确版本的 chromedriver 功能有同学用过吗?

漆黑小牙牙 · 2018年09月05日 · 最后由 tangkai 回复于 2020年07月29日 · 718 次阅读

Appium 关键字 chromedriverChromeMappingFile 和 chromedriverExecutableDir。
目前调试下来只有一款原生安卓的 moto 手机是可以正确选择当前手机的 webview 版本和电脑上的 chromedriver 映射匹配的,国产手机均不能正确匹配,只会选择当前电脑中最新的 chromedriver 版本,报错:Unable to discover Chrome version. Using Chromedriver 2.41 at XXXXX,不知道该怎么解决。

共收到 11 条回复 时间 点赞

日志贴出来,我用了下是没问题的,另外 1.8.0 可能有问题的,最好用 1.8.1 或者 1.9.0 试试

雨夜狂奔 回复

[HTTP]
[HTTP] --> POST /wd/hub/session/78435b13-ccb6-48fd-a611-511380dcaba7/context
[HTTP] {"name":"WEBVIEW_stetho_com.baosight.carsharing:remote"}
[Chromedriver] Unable to discover Chrome version. Using Chromedriver 2.41 at '/Users/jinwei/Documents/ChromeDriver/2.41'
[Chromedriver] Set chromedriver binary as: /Users/jinwei/Documents/ChromeDriver/2.41
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: /Users/jinwei/Documents/ChromeDriver/2.41 --url-base=wd/hub --port=8000 --adb-port=5037 --verbose
[Chromedriver] Error: Failed to start Chromedriver session: A new session could not be created. Details: session not created exception: Chrome version must be >= 67.0.3396.0
Chromedriver
[Chromedriver] at Object.wrappedLogger.errorAndThrow (/usr/local/lib/node_modules/appium/node_modules/appium-support/lib/logging.js:78:13)
[Chromedriver] at Chromedriver.callee$2$0$ (/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/lib/chromedriver.js:448:13)
[Chromedriver] at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
[Chromedriver] at GeneratorFunctionPrototype.invoke as _invoke
[Chromedriver] at GeneratorFunctionPrototype.prototype.(anonymous function) as throw

Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[Chromedriver] Unable to automate Chrome version because it is too old for this version of Chromedriver.

[Chromedriver] Chrome version on device: Chrome/55.0.2883.91

[Chromedriver] Please see 'https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md'
[Chromedriver] Error: Failed to start Chromedriver session: A new session could not be created. Details: session not created exception: Chrome version must be >= 67.0.3396.0
Chromedriver

看日志,一开始获取手机 chrome 版本的时候获取不到,直接使用了当前最高的 2.41 版本导致版本不匹配报错,但是后续的日志又能识别出 Chrome version on device: Chrome/55.0.2883.91 ,看了 appium 的源码,源码在在判 chromedriver 版本的逻辑为 chromeVersion = chromeVersion ? semver.coerce(chromeVersion) : null; 我感觉我的情况应该是 chromedriver 为 null,但是 不清楚为什么。。。

雨夜狂奔 回复

附上 cap 和 mapping 文件
{
"android": {
"platformName": "android",
"platformVersion": "",
"deviceName": "android",
"app": "./build/xx.apk",
"appPackage": "com.xx.xx",
"appActivity": "com.xx.activity.AppStartActivity",
"noSign": true,
"unicodeKeyboard": true,
"resetKeyboard": true,
"noReset": true,
"recreateChromeDriverSessions": true,
"automationName": "UiAutomator2",
"uiautomator2ServerInstallTimeout": 300000,
"newCommandTimeout": 500,
"chromedriverChromeMappingFile": "/xxxxxx/caps/chromeDriverMapping.json",
"chromedriverExecutableDir": "/xx/xx/Documents/ChromeDriver"
},

{
"2.41": "67.0.3360",
"2.40": "66.0.3359",
"2.38": "65.0.3325",
"2.37": "64.0.3282",
"2.36": "63.0.3239",
"2.35": "62.0.3202",
"2.34": "61.0.3163",
"2.33": "60.0.3112",
"2.32": "59.0.3071",
"2.31": "58.0.3029",
"2.29": "57.0.2987",
"2.28": "55.0.2883",
"2.27": "54.0.2840",
"2.26": "53.0.2785",
"2.24": "52.0.2743",
"2.23": "51.0.2704",
"2.22": "49.0.2623"
}

[Chromedriver] Unable to discover Chrome version. Using Chromedriver 2.41,要看这段日志之前的 log,appium 找版本的过程

找到你浏览器版本匹配的 Chromedriver .exe,把它替换到日志里面写的 chrome driver.exe 位置即可

。。并没有找的日志,上面都是业务逻辑的 log 了,[HTTP] --> POST /wd/hub/session/78435b13-ccb6-48fd-a611-511380dcaba7/context
[HTTP] {"name":"WEBVIEW_stetho_com.baosight.carsharing:remote"} 这一步就是切 h5 切句柄开始了,能看到找版本的过程的 log,我都搞定了。。。

Dodo 回复

并发 40 台机器,不可能这样替换的,chromedriver 目前只有 2 种方案,一个是启动 server 的时候就明确的指出每个手线程对应的每个手机用哪个 chromedriver,直接启动,另外一个就是使用这个新关键字,在切 h5 句柄的时候动态获取在启动

已解决,谢谢

怎么解决的。我这儿也是找不对对应的 Chromedriver
看日志是有加载所有 driver 的

[debug] [Chromedriver] Found 13 executables in '/Users/yupan/Documents/workspace/chromedriver/'
[debug] [Chromedriver] The following Chromedriver executables were found:
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.41 (minimum Chrome version '67.0.3396')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.40 (minimum Chrome version '66.0.3359')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.39 (minimum Chrome version '66.0.3359')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.38 (minimum Chrome version '65.0.3325')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.37 (minimum Chrome version '64.0.3282')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.36 (minimum Chrome version '63.0.3239')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.35 (minimum Chrome version '62.0.3202')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.34 (minimum Chrome version '61.0.3163')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.33 (minimum Chrome version '60.0.3112')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.32 (minimum Chrome version '59.0.3071')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.31 (minimum Chrome version '58.0.3029')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.30 (minimum Chrome version '58.0.3029')
[debug] [Chromedriver]     /Users/yupan/Documents/workspace/chromedriver/chromedriver_2.29 (minimum Chrome version '57.0.2987')
[debug] [ADB] Device API level: 23
[debug] [ADB] Getting package info for 'com.google.android.webview'
[debug] [ADB] Running '/Users/yupan/Downloads/programfile/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb -P 5037 -s LE67A06300364337 shell dumpsys package com.google.android.webview'
[debug] [ADB] Getting package info for 'com.android.webview'
[debug] [ADB] Running '/Users/yupan/Downloads/programfile/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb -P 5037 -s LE67A06300364337 shell dumpsys package com.android.webview'
[debug] [ADB] Getting package info for 'com.android.chrome'
[debug] [ADB] Running '/Users/yupan/Downloads/programfile/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb -P 5037 -s LE67A06300364337 shell dumpsys package com.android.chrome'
[debug] [Chromedriver] Found Chrome bundle 'com.android.chrome' version '56.0.2924'
[Chromedriver] Error: No Chromedriver found that can automate Chrome '56.0.2924'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details.
[Chromedriver]     at Object.wrappedLogger.errorAndThrow (/usr/local/lib/node_modules/appium/node_modules/_appium-support@2.20.0@appium-support/lib/logging.js:78:13)
[Chromedriver]     at Chromedriver.getCompatibleChromedriver$ (/usr/local/lib/node_modules/appium/node_modules/_appium-chromedriver@4.4.0@appium-chromedriver/lib/chromedriver.js:256:11)
[Chromedriver]     at tryCatch (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:67:40)
[Chromedriver]     at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/_babel-runtime@5.8.24@babel-runtime/regenerator/runtime.js:315:22)

怎么解决的

自动选择版本的原理是查 package 里 chrome 的版本,国产手机的 package 名都改了,比如华为的是 com.huawei.webview。为了让国产手机能识别到,要手动在手机上装一个 chrome,版本和系统自带的 webview 版本相同,这样 appium 就能找到了。

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