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

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


↙↙↙阅读原文可查看相关链接,并与作者交流