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 [email protected] 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)