Fail to use 2 instances of Appium for 2 USB connected Android devices

Works fine in same setup if only 1 device connected via USB. e.g. still 2 instances of Appium, but 1 device connected, and the driver session specifies which instance/port of Appium to connect to.

With 2 devices, even while specifying specifically which instance/port to connect to, it fails to launch the app under test (for even just one device, not talking about parallel execution yet, only parallel appium instances running at the moment) and driver session throws exception. Details error & logs below. Based on some of the output, seems appium or rather adb canā€™t handle dealing with multiple connected devices.

I think Iā€™m using latest Android SDK/adb (adb v1.0.32) that I got off colleague and then ran some updates on it to pull for API 23 / Android 6. Iā€™m using latest version of appium for both node.js binary (used here) as well as Appium.app. As for device connection, I just had the Android Moto Eā€™s enabled for USB debugging, and connected via USB to my Mac. Nothing more done.

How do I set up my environment such that Appium and adb can deal with multiple connected devices and know to route to which device? Looking at some appium docs (starting from http://appium.io/slate/en/master/?ruby#server-flags) I canā€™t tell how you can map an Appium instance to a specific device, or point out to which one as well in the desired capabilities, assuming you have 2x of the same device type. At least on iOS, thereā€™s the UDID parameter.

In my appium instance launch, itā€™s the same startup parameters (see below) other than different ports.

(python) client error:
d = webdriver.Remote( command_executor=ā€˜http://127.0.0.1:8081/wd/hubā€™, desired_capabilities={ā€˜platformNameā€™:ā€˜Androidā€™,ā€˜platformVersionā€™:ā€˜5.1ā€™,ā€˜device IDā€™:ā€˜00000000-0000-0000-0000-e4907e2df4baā€™,ā€˜deviceNameā€™:ā€˜Moto Eā€™})
Traceback (most recent call last):
File ā€œā€, line 1, in
File ā€œ/usr/local/lib/python2.7/site-packages/appium/webdriver/webdriver.pyā€, line 36, in init
super(WebDriver, self).init(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
File ā€œ/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyā€, line 87, in init
self.start_session(desired_capabilities, browser_profile)
File ā€œ/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyā€, line 141, in start_session
ā€˜desiredCapabilitiesā€™: desired_capabilities,
File ā€œ/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.pyā€, line 201, in execute
self.error_handler.check_response(response)
File ā€œ/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.pyā€, line 181, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Cannot read property ā€˜stopā€™ of undefined

Appium server logs:
appium --port ā€˜8081ā€™ --command-timeout ā€˜7200ā€™ --debug-log-spacing --automation-name ā€˜Appiumā€™ --platform-name ā€˜Androidā€™ --platform-version ā€˜5.1ā€™ --app ā€œ/pathTo/app.apkā€
[Appium] Welcome to Appium v1.5.0-beta9 (REV ad64e01ff4e4569f6a1e8c09b480d9c045aaf513)
[Appium] Appium REST http interface listener started on 0.0.0.0:8081
[Appium] Non-default server args:
[Appium] port: 8081
[Appium] defaultCommandTimeout: 7200
[Appium] debugLogSpacing: true
[Appium] platformName: Android
[Appium] platformVersion: 5.1
[Appium] automationName: Appium
[Appium] app: /pathTo/app.apk
[Appium] Deprecated server args:
[Appium] --platform-name => --default-capabilities ā€˜{ā€œplatformNameā€:ā€œAndroidā€}ā€™
[Appium] --platform-version => --default-capabilities ā€˜{ā€œplatformVersionā€:ā€œ5.1ā€}ā€™
[Appium] --automation-name => --default-capabilities ā€˜{ā€œautomationNameā€:ā€œAppiumā€}ā€™
[Appium] --app => --default-capabilities ā€˜{ā€œappā€:"/pathTo/app.apk"}ā€™
[Appium] Default capabilities, which will be added to each request unless overridden by desired capabilities: {ā€œplatformNameā€:ā€œAndroidā€,ā€œplatformVersionā€:ā€œ5.1ā€,ā€œautomationNameā€:ā€œAppiumā€,ā€œappā€:"/pathTo/app.apk"}
[HTTP] --> POST /wd/hub/session
[MJSONWP] Calling AppiumDriver.createSession() with args: [{ā€œplatformVersionā€:ā€œ5.1ā€,ā€œdevice IDā€:ā€œ00000000-0000-0000-0000-e4907e2df4baā€,ā€œplatformNameā€:ā€œAndroidā€,ā€œdeviceNameā€:ā€œMoto Eā€},null,null,null]
[Appium] Creating new AndroidDriver session
[BaseDriver] The following capabilities were provided, but are not recognized by appium: device ID.
[BaseDriver] Session created with session id: 7e2ffd8e-f2c8-498f-9cc5-0a505445910b
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_66
[ADB] Checking whether adb is present
[ADB] Using adb from /Applications/AndroidDev/sdk/platform-tools/adb
[BaseDriver] Using local app ā€˜/pathTo/app.apkā€™
[debug] [AndroidDriver] Checking whether app is actually present
[AndroidDriver] Starting Android session
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[AndroidDriver] Found device: TA0930ALF7
[debug] [ADB] Setting device id to TA0930ALF7
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œwait-for-deviceā€]
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œechoā€,ā€œpingā€]
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Pushing settings apk to deviceā€¦
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œinstallā€,"/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/io.appium.settings/bin/settings_apk-debug.apk"]
[debug] [AndroidDriver] Pushing unlock helper app to deviceā€¦
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œinstallā€,"/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-unlock/bin/unlock_apk-debug.apk"]
[ADB] Getting device platform version
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œgetpropā€,ā€œro.build.version.releaseā€]
[debug] [AndroidDriver] Parsing package and activity from app manifest
[ADB] Checking whether aapt is present
[ADB] Using aapt from /Applications/AndroidDev/sdk/build-tools/23.0.2/aapt
[ADB] Extracting package and launch activity from manifest
[debug] [ADB] badging package: com.blah.blah
[debug] [ADB] badging act: com.blah.blah.MainActivity
[debug] [AndroidDriver] Parsed package and activity are: com.blah.blah/com.blah.blah.MainActivity
[debug] [ADB] Uninstalling com.blah.blah
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œamā€,ā€œforce-stopā€,ā€œcom.blah.blahā€]
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œuninstallā€,ā€œcom.blah.blahā€]
[ADB] App was not uninstalled, maybe it wasnā€™t on device?
[AndroidDriver] Remote apk path is /data/local/tmp/8e431a8da3b643581864d3ea5f739fe2.apk
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œlsā€,"/data/local/tmp/8e431a8da3b643581864d3ea5f739fe2.apk"]
[debug] [AndroidDriver] Checking if app is installed
[debug] [ADB] Getting install status for com.blah.blah
[ADB] Getting device API level
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œgetpropā€,ā€œro.build.version.sdkā€]
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œpmā€,ā€œlistā€,ā€œpackagesā€,"-3",ā€œcom.blah.blahā€]
[debug] [ADB] App is not installed
[AndroidDriver] Apk is not yet installed
[AndroidDriver] installing apk from remote
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œmkdirā€,"-p","/data/local/tmp"]
[AndroidDriver] Clearing out any existing remote apks with the same hash
[debug] [AndroidDriver] Removing any old apks
[debug] [AndroidDriver] Except [ā€œ8e431a8da3b643581864d3ea5f739fe2ā€]
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œlsā€,"/data/local/tmp/*.apk"]
[AndroidDriver] Will remove /data/local/tmp/528e2c0a377acc7792bcb08d60b687d9.apk
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œrmā€,"/data/local/tmp/528e2c0a377acc7792bcb08d60b687d9.apk"]
[AndroidDriver] Pushing com.blah.blah to device. Will wait up to 90000 milliseconds before aborting
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œpushā€,"/pathTo/app.apk","/data/local/tmp/8e431a8da3b643581864d3ea5f739fe2.apk"]
[debug] [ADB] Uninstalling com.blah.blah
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œamā€,ā€œforce-stopā€,ā€œcom.blah.blahā€]
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œuninstallā€,ā€œcom.blah.blahā€]
[ADB] App was not uninstalled, maybe it wasnā€™t on device?
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œpmā€,ā€œinstallā€,"-r","/data/local/tmp/8e431a8da3b643581864d3ea5f739fe2.apk"]
[debug] [AndroidDriver] Extracting strings from apk /pathTo/app.apk null /var/folders/n3/cqw987rs0n58txvdnkgssb3w0000gn/T/com.blah.blah
[debug] [ADB] Extracting strings for language: default
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œgetpropā€,ā€œpersist.sys.languageā€]
[debug] [ADB] Current device property ā€˜persist.sys.languageā€™:
[debug] [ADB] No strings.xml for language ā€˜ā€™, getting default strings.xml
[debug] [ADB] Reading strings from converted strings.json
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œpushā€,"/var/folders/n3/cqw987rs0n58txvdnkgssb3w0000gn/T/com.blah.blah/strings.json","/data/local/tmp"]
[ADB] Checking whether adb is present
[ADB] Using adb from /Applications/AndroidDev/sdk/platform-tools/adb
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: [ā€œforwardā€,ā€œtcp:4724ā€,ā€œtcp:4724ā€]
[debug] [UiAutomator] Starting UiAutomator
[debug] [UiAutomator] Moving to state ā€˜startingā€™
[debug] [UiAutomator] Parsing uiautomator jar
[debug] [UiAutomator] Found jar name: ā€˜AppiumBootstrap.jarā€™
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: [ā€œpushā€,"/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar","/data/local/tmp/"]
[ADB] Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb forward tcp:4724 tcp:4724ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}
at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
at ADB.execFunc$ (lib/tools/system-calls.js:188:11)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at run (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)
at /usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:115:28
at flush (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:19:5)
at process._tickCallback (node.js:355:11)
[Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb forward tcp:4724 tcp:4724ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}]
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: [ā€œforwardā€,ā€œtcp:4724ā€,ā€œtcp:4724ā€]
[ADB] Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}
at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
at ADB.execFunc$ (lib/tools/system-calls.js:188:11)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at run (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)
at /usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:115:28
at flush (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:19:5)
at process._tickCallback (node.js:355:11)
[Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}]
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: [ā€œpushā€,"/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar","/data/local/tmp/"]
[ADB] Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb forward tcp:4724 tcp:4724ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}
at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
at ADB.execFunc$ (lib/tools/system-calls.js:188:11)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at run (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)
at /usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:115:28
at flush (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:19:5)
at process._tickCallback (node.js:355:11)
[Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb forward tcp:4724 tcp:4724ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}]
[ADB] Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}
at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
at ADB.execFunc$ (lib/tools/system-calls.js:188:11)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at run (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)
at /usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:115:28
at flush (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:19:5)
at process._tickCallback (node.js:355:11)
[Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}]
[UiAutomator] Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}
at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
at ADB.execFunc$ (lib/tools/system-calls.js:188:11)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at run (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)
at /usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:115:28
at flush (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:19:5)
at process._tickCallback (node.js:355:11)
[Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}]
[AndroidBootstrap] Error: Error occured while starting AndroidBootstrap. Original error: Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}
at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
at AndroidBootstrap.start$ (lib/bootstrap.js:89:11)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at run (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)
at /usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:115:28
at flush (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:19:5)
at process._tickCallback (node.js:355:11)
[Error: Error occured while starting AndroidBootstrap. Original error: Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb push /usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar /data/local/tmp/ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}]
[debug] [AndroidDriver] Shutting down Android driver
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œamā€,ā€œforce-stopā€,ā€œcom.blah.blahā€]
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 2 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œinputā€,ā€œkeyeventā€,3]
[debug] [Logcat] Stopping logcat capture
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state ā€˜stoppingā€™
[MJSONWP] Encountered internal error running command: TypeError: Cannot read property ā€˜stopā€™ of undefined
at UiAutomator.shutdown$ (lib/uiautomator.js:69:20)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at enqueueResult (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
at new Promise (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:197:7)
at AsyncIterator.enqueue (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:16)
at AsyncIterator.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at Object.runtime.async (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
at UiAutomator.shutdown (lib/uiautomator.js:66:18)
at AndroidBootstrap.shutdown$ (lib/bootstrap.js:140:28)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at enqueueResult (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
at new Promise (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:197:7)
at AsyncIterator.enqueue (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:16)
at AsyncIterator.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at Object.runtime.async (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
at AndroidBootstrap.shutdown (lib/bootstrap.js:129:18)
at AndroidDriver.deleteSession$ (lib/driver.js:276:28)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at run (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)
at /usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:115:28
at flush (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:19:5)
at process._tickCallback (node.js:355:11)
[HTTP] <-- POST /wd/hub/session 500 17963.897 ms - 177
^C

pardon me for lack of knowledge of adb & any of its settings on Appium, Iā€™m a novice to mobile app automation. I assume Iā€™m missing some specific trick one needs to do when dealing with multiple devices that you normally donā€™t need to worry about for single device setup.

use udid instead of device ID in caps,
eg. "udid":"e4907e2df4ba"

P.S. If logs are more than 20 lines please prefer using gist, It really helps while checking these logs.

Gave specifying UDID a try, it appears that does not work over USB. Appium calls ADB and that still detects 3 devices and gets confused. So looks like I have to try other methods:

  • ADB connection over wifi (rather than USB)
  • Run Appium & adb within Mac VM to deal with the device list over USB (similar to iOS instruments limit of 1 device per Mac). Then assign VM USB connection for 2nd and 3rd devices, with 1st connected to the physical Mac. This worked for me, while I was testing out for iOS, tried for Android as well.

Just tried over wifi for adb connection as well, it seems Appium + adb doesnā€™t like multiple devices connected to same machine, even with UDID specified, it doesnā€™t know how to pick.

So whether by USB or wifi, youā€™ll need multiple machines or use VMs on a single machine to be able to scale to multiple devices in parallel.

I took a look at https://github.com/appium/appium/issues/462 and tried suggestions there.

  • used udid in desired capability for client
  • passed udid/U flag on appium server instance (ran 2 instances on different ports)
  • passed a different -bp port value for each appium server instance
  • added --session-override flag to both appium server instances

still no go with 2 Android devices connected, rather than link/post long log snippet, this is what might be of interest to see for excerpts:

here we detect multiple devices connected, and issue command to correct device UDID

[debug] [ADB] Getting connected devicesā€¦
[debug] [ADB] 3 device(s) connected
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: ["-s",ā€œTA0930ALF7ā€,ā€œshellā€,ā€œpmā€,ā€œinstallā€,"-r","/data/local/tmp/8e431a8da3b643581864d3ea5f739fe2.apk"]

and hereā€™s where it finally fails

[debug] [UiAutomator] Found jar name: ā€˜AppiumBootstrap.jarā€™
[debug] [ADB] Running /Applications/AndroidDev/sdk/platform-tools/adb with args: [ā€œpushā€,"/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar","/data/local/tmp/"]
[ADB] Error: Error executing adbExec. Original error: Command ā€˜/Applications/AndroidDev/sdk/platform-tools/adb forward tcp:4724 tcp:4724ā€™ exited with code 1{ā€œstdoutā€:"",ā€œstderrā€:ā€œerror: more than one device/emulator\nā€,ā€œcodeā€:1}

My environment:

Appium node.js version 1.5.0-beta9
node.js version 0.12.4
adb version 1.0.32 Revision 09a0d98bebce-android
Mac OS X 10.10.5
Using Appium Python client, should be the latest

Try with appium version 1.4.16

Hi @daluu
I got a same problem with you! The error is: WebDriverException: Message: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c ā€œD:\android-sdk-6.0\platform-tools\adb.exe shell ā€œgetprop persist.sys.languageā€ā€
error: more than one device/emulator

so, have you found some ways to solve your problem?
I use Appium 1.4.16.1, and below is my script(python) and my settings in Appium:

  1. my python script:

#coding=utf-8
from appium import webdriver
from threading import Thread

def test(platformVersion,deviceName,port,udid):
desired_caps = {}
desired_caps[ā€˜platformNameā€™] = ā€˜Androidā€™
desired_caps[ā€˜platformVersionā€™] = platformVersion
desired_caps[ā€˜deviceNameā€™] = deviceName
desired_caps[ā€˜udidā€™] = udid
desired_caps[ā€˜appPackageā€™] = ā€˜com.android.calculator2ā€™
desired_caps[ā€˜appActivityā€™] = ā€˜.Calculatorā€™

driver = webdriver.Remote('http://localhost:%s/wd/hub' % port, desired_caps)

driver.find_element_by_name("1").click()

driver.find_element_by_name("5").click()

driver.find_element_by_name("9").click()

driver.find_element_by_name("delete").click()

driver.find_element_by_name("9").click()

driver.find_element_by_name("5").click()

driver.find_element_by_name("+").click()

driver.find_element_by_name("6").click()

driver.find_element_by_name("=").click()

driver.quit()

class MyThread(Thread):
def init(self,platformVersion,deviceName,port,udid):
super(MyThread, self).init()
self.platformVersion=platformVersion
self.deviceName=deviceName
self.port=port
self.udid=udid

def run(self):
    test(self.platformVersion,self.deviceName,self.port,self.udid)

t1=MyThread(ā€˜5.0.2 LRX22Gā€™,ā€˜MI 2SCā€™,ā€˜4723ā€™,ā€˜cfccd0f5ā€™)
t2=MyThread(ā€˜5.0.1ā€™,ā€˜GT-I9500ā€™,ā€˜4725ā€™,ā€˜4d0088c04e0011b5ā€™)
t1.start()
t2.start()

  1. my settings in Appium:
    1. appium setting 1st:


      2)appium setting 2nd:

  2. I can find my 2 devices are online:

or someone else can help me? I really appreciate that!

@pr4bh4sh Hi! I tried 1.4.16.1, but still got the same error, can you help me out?
My all setttings and script are above.

I found that when appium try to send command via adb:


adb found more than 1 devices, so I tried mannuallyļ¼š

itā€™s the same result as in Appium log.
and I tried a second time as this:

it can return expected result!
And now the question is: How and where to make appium a change so that it can send command with specified device?

Any help is with great appreciate!

Iā€™m on mac, and iā€™ve installed Appium from npm. However Appium version on my machine is 1.4.16 not 1.4.16.1.
It is working for me when more than 2 android devices are connected.
Can you install it from npm and then try?
Steps:

  1. Install node.js binary from Node.js website.
  2. After installation open command prompt and type
    npm -g install [email protected] and press Enter.
  3. After installation run appium on command prompt.(it will start the server at 4723)
  4. Run you test cases.

Thanks @pr4bh4sh
Iā€™ve solved my problem just now, but it works with another change as below!
By this: I changed my script from before to this:

And I suggest to @daluu
U can have a try like mine: 1. make caps.deviceName=udid, thatā€™s ur android sequence No.;
2. add udid in caps(which may not needed if u just test only ONE device) and make udid=udid

Now my testing works well, thank you all guys.

2 Likes

@Real_Lau Glad you are finally able to solve it.

For anyone comes to this post in future:
UDID is the way Appium server differentiates between two devices, not by deviceName. If you donā€™t provide the udid the server assumes that there is only one device and tries to install or send command to the default connected device without mentioning the android device id.
i.e. it tries adb install <*.apk> rather than adb -s <android_ id> install <*.apk>

which gets failed because ADB throws the error that ā€œThere are multiple device connectedā€.

@pr4bh4sh thanks for the tip (and the comment in the referenced Github issue). Got it to work for 3 devices with Appium v1.4.16 (2 over USB, one over wifi with 3 appium instances).

On a related note, itā€™s funny how I got appium node.js version 1.5.0-beta9 installed. I believe I had installed it via the standard instructions mentioned at appium.io (but I could be wrong). On uninstalling then reinstalling, this time a regular npm install -g appium correctly installed 1.4.16 (which appears to be latest stable version excluding betas based on the web node repo listings).

@daluu Glad it worked.
On how you got the unintended version.

  1. In you donā€™t specify the version while installing it via npm e.g. npm -g install appium it will install whatever latest stable.
  2. While installing beta if you do npm -g install appium@beta it will install the latest beta avaliable. I guess thats how you got the beta9. Suppose you want the 1.5.0 beta8 then npm -g install [email protected] should do the trick.

You should try avm if you want more than one version of Appium available all the time without installing them every time.
P.S. You can also look at https://github.com/saikrishna321/AppiumTestDistribution as @saikrishna321 has suggested on git.

Thanks for the tip on avm, that will be helpful. Btw, I never explicitly tagged @beta at the end to my original instal (no tag at all supposedly)l. I guess npm screwed up there somehow, worked ok the second time around.

As for AppiumTestDistribution, it looks like cool solution but is built for Java. Would be nice if weā€™ll eventually get a port for other platforms like Python (Iā€™m using Python client for Appium). Or better yet, a language agnostic platform akin to Selenium Grid, where you just connect to it & it (or you manually) handle all the parallel instance handling on the back end.

Yeh, NPM might be the culprit here.
About the AppiumumTestDistribution, So itā€™s gonna hard for me too. As Iā€™m planning to switch to python as well. Iā€™ll try to recreate the same with python, but not anytime soon.

Hi Daluu,

I am getting the ā€˜more than one device/emulatorā€™ error too.

I tried everything in this post but no success yet.

I even tried to spawn 2 adb instances on different ports but appium doesnā€™t know how to talk to the 2nd adb instance.

I guess you didnā€™t have to do that.

Did you have this in your capabilities?

I was using adb tcpip so I had this

"deviceName": "10.10.122.130:5555",
    "udid": "10.10.122.130:5555",

Did you have to use deviceName? or did you only have to use udid?

Figured it out:

For future reference, I had to tinker with the following:

  1. Update dotnet client driver to 1.5.0.1
  2. Install appium-android-driver 1.6.6
    https://github.com/appium/appium/issues/6112
  3. Install [email protected]

Hello pr4bh4sh,

I tried following your approach, but it still doesā€™nt work for me. Pasting the logs below.

2016-02-22 07:12:59:428 - info: ā†’ GET /wd/hub/session/eee391c3-b426-40f0-8aab-415f2fef508c {}
2016-02-22 07:12:59:429 - info: [debug] Responding to client with success: {ā€œstatusā€:0,ā€œvalueā€:{ā€œplatformā€:ā€œLINUXā€,ā€œbrowserNameā€:ā€œAndroidā€,ā€œplatformVersionā€:ā€œ18ā€,ā€œwebStorageEnabledā€:false,ā€œtakesScreenshotā€:true,ā€œjavascriptEnabledā€:true,ā€œdatabaseEnabledā€:false,ā€œnetworkConnectionEnabledā€:true,ā€œlocationContextEnabledā€:false,ā€œwarningsā€:{},ā€œdesiredā€:{ā€œplatformVersionā€:ā€œ18ā€,ā€œdeviceNameā€:ā€œFSMARTā€,ā€œautoLaunchā€:false,ā€œplatformNameā€:ā€œAndroidā€,ā€œudidā€:ā€œ4df7f8d8260f3093ā€},ā€œdeviceNameā€:ā€œFSMARTā€,ā€œautoLaunchā€:false,ā€œplatformNameā€:ā€œAndroidā€,ā€œudidā€:ā€œ4df7f8d8260f3093ā€},ā€œsessionIdā€:ā€œeee391c3-b426-40f0-8aab-415f2fef508cā€}

2016-02-22 07:12:59:432 - info: ā† GET /wd/hub/session/eee391c3-b426-40f0-8aab-415f2fef508c 200 4.117 ms - 533 {ā€œstatusā€:0,ā€œvalueā€:{ā€œplatformā€:ā€œLINUXā€,ā€œbrowserNameā€:ā€œAndroidā€,ā€œplatformVersionā€:ā€œ18ā€,ā€œwebStorageEnabledā€:false,ā€œtakesScreenshotā€:true,ā€œjavascriptEnabledā€:true,ā€œdatabaseEnabledā€:false,ā€œnetworkConnectionEnabledā€:true,ā€œlocationContextEnabledā€:false,ā€œwarningsā€:{},ā€œdesiredā€:{ā€œplatformVersionā€:ā€œ18ā€,ā€œdeviceNameā€:ā€œFSMARTā€,ā€œautoLaunchā€:false,ā€œplatformNameā€:ā€œAndroidā€,ā€œudidā€:ā€œ4df7f8d8260f3093ā€},ā€œdeviceNameā€:ā€œFSMARTā€,ā€œautoLaunchā€:false,ā€œplatformNameā€:ā€œAndroidā€,ā€œudidā€:ā€œ4df7f8d8260f3093ā€},ā€œsessionIdā€:ā€œeee391c3-b426-40f0-8aab-415f2fef508cā€}

2016-02-22 07:12:59:467 - info: [debug] Getting install status for com...dev
2016-02-22 07:12:59:467 - info: [debug] Getting device API level
2016-02-22 07:12:59:468 - info: [debug] executing cmd: C:\Users\z185805\AppData\Local\Android\sdk\platform-tools\adb.exe shell ā€œgetprop ro.build.version.sdkā€
2016-02-22 07:12:59:703 - warn: Error: Command failed: C:\Windows\system32\cmd.exe /s /c ā€œC:\Users\z185805\AppData\Local\Android\sdk\platform-tools\adb.exe shell ā€œgetprop ro.build.version.sdkā€ā€
error: more than one device and emulator

at ChildProcess.exithandler (child_process.js:751:12)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1016:16)
at Process.ChildProcess._handle.onexit (child_process.js:1088:5)