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

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)

Which version of appium server you are using???
Configuration looks correct.

The version I’m using is 1.4.16.1

And this is in Appium in Windows machine.

in your case,

  1. You can launch two appium server instances, each server instance bind with one device. to do this you need to provide -UDID as command line argument while launching appium
    e.g: appium -p 6001 -u <Device 1 UDID>

  2. allocate different appium servers only with Unique port, and you can provide UDID to your desired capability.

Thanks,
Priyank Shah

I am having a very similar issue as you guys, I added a comment on an issue on github https://github.com/appium/appium/issues/5949#issuecomment-216656313 any help would be really appreciated.

Minor difference is that I am using Selenium as a hub, but I think the issue is stemming from the actual appium servers. It seems to be ignoring the caps? The only thing I haven’t tried is downgrading to 1.4.16, is that even worth it at this point?

Thanks!

I just skimmed the Github issue, but I think the bug occurred in one of the projects Appium depends on. npm, however, might not automatically install the latest versions of all the dependencies.

You want to install Appium through npm using the --no-shrinkwrap option, which forces npm to install the latest published versions of all the projects Appium depends on for everything.

Thanks for the quick reply @afwang, I tried that and still got the same result.