Appium appium 1.8.0 中的 deviceName 为什么不起作用了

cheung · 2018年11月07日 · 最后由 Sky 回复于 2021年05月20日 · 3911 次阅读
Appium] Appium REST http interface listener started on 0.0.0.0:4724
[HTTP] --> POST /wd/hub/session
[HTTP] {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"platformName":"Android","appium:platformVersion":"8.0.0","appium:deviceName":"b493a8","appium:appPackage":"com.dadaabc.zhuozan.dadaabcstudent","appium:appActivity":".ui.activitys.SplashScreenActivity","appium:newCommandTimeout":3600,"appium:resetKeyboard":true,"appium:noReset":null,"appium:fullReset":null,"appium:noSign":true,"appium:autoGrantPermissions":true,"appium:app":"/home/appium/com.dadaabc.zhuozan.dadaabcstudent.apk","appium:automationName":"UiAutomator2","appium:systemPort":8201,"appium:brand":"SM-G3900"}},"desiredCapabilities":{"platformName":"Android","platformVersion":"8.0.0","deviceName":"b493a8","appPackage":"com.dadaabc.zhuozan.dadaabcstudent","appActivity":".ui.activitys.SplashScreenActivity","newCommandTimeout":3600,"resetKeyboard":true,"noReset":null,"fullReset":null,"noSign":true,"autoGrantPermissions":true,"app":"/home/appium/com.dadaabc.zhuozan.dadaabcstudent.apk","automationName":"UiAutomator2","systemPort":8201,
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","platformVersion":"8.0.0","deviceName":"b493a8","appPackage":"com.dadaabc.zhuozan.dadaabcstudent","appActivity":".ui.activitys.SplashScreenActivity","newCommandTimeout":3600,"resetKeyboard":true,"noReset":null,"fullReset":null,"noSign":true,"autoGrantPermissions":true,"app":"/home/appium/com.dadaabc.zhuozan.dadaabcstudent.apk","automationName":"UiAutomator2","systemPort":8201,"brand":"SM-G3900"},null,{"firstMatch":[{}],"alwaysMatch":{"platformName":"Android","appium:platformVersion":"8.0.0","appium:deviceName":"b493a8","appium:appPackage":"com.dadaabc.zhuozan.dadaabcstudent","appium:appActivity":".ui.activitys.SplashScreenActivity","appium:newCommandTimeout":3600,"appium:resetKeyboard":true,"appium:noReset":null,"appium:fullReset":null,"appium:noSign":true,"appium:autoGrantPermissions":true,"appium:app":"/home/appium/com.dadaabc.zhuozan.dadaabcstudent.apk","appium:automationName":"UiAutomator2","appium:systemPort":8201,"appium:brand":"SM-G3900"}}]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 4 device(s) connected
[AndroidDriver] Looking for a device with Android '8.0.0'
[debug] [ADB] Setting device id to QDY7N17412007934
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 4 device(s) connected
[debug] [ADB] Running '/home/appium/androidSdk/platform-tools/adb -P 5037 -s QDY7N17412007934 shell getprop ro.build.version.release'
[debug] [ADB] Current device property 'ro.build.version.release': 7.0
[debug] [ADB] Setting device id to b493a8a2
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 4 device(s) connected
[debug] [ADB] Running '/home/appium/androidSdk/platform-tools/adb -P 5037 -s b493a8a2 shell getprop ro.build.version.release'
[debug] [ADB] Current device property 'ro.build.version.release': 8.0.0
[AndroidDriver] Using device: b493a8a2
[ADB] Checking whether adb is present
[ADB] Using adb from /home/appium/androidSdk/platform-tools/adb
[debug] [ADB] Setting device id to b493a8a2

首先我把指定的 deviceName 故意写错了

{"platformName":"Android","appium:platformVersion":"8.0.0","appium:deviceName":"b493a8","appium:appPackage":"com.dadaabc.zhuozan.dadaabcstudent","appium:appActivity":".ui.activitys.SplashScreenActivity","appium:newCommandTimeout":3600,"appium:resetKeyboard":true,"appium:noReset":null,"appium:fullReset":null,"appium:noSign":true,"appium:autoGrantPermissions":true,"appium:app":"/home/appium/com.dadaabc.zhuozan.dadaabcstudent.apk","appium:automationName":"UiAutomator2","appium:systemPort":8201,"appium:brand":"SM-G3900"}}

从 log 中很清楚的看到,appium 判断指定设备是通过系统版本去做的,

[AndroidDriver] Looking for a device with Android '8.0.0'

找到匹配的系统版本后,然后才指定设备 id,跟脚本中传的 deviceName 没有任何关系

[debug] [ADB] Setting device id to b493a8a2

所以问题就来了,如果两个手机的系统版本一样的话,每次连的就会是第一个系统版本匹配的手机

共收到 5 条回复 时间 点赞

devicesname 是没有用的随便写都可以,但是必须要写,不能没有这个参数

指定 udid 才有用,Android 上面 deviceName 貌似没啥用,udid 也是 adb devices 里的 id 就行了

deviceName 一直没用,最近的版本把 udid 当成要选择的设备了。

我之前在调试的时候遇到: 2 台真机 系统版本一样,型号一样,udid 不一样,在 run 的时候都只有一台机器运行。 我也想知道,怎样让 2 台真机 (仅 udid 不一样) 启动?

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