Launching avd through desired capabilities

Hello,

I have a quick question on how to launch an android avd by passing the avd name in the desired capabilities flags. I have looked at the documentation and there is a desired capability flag, avd, which when supplied with an ‘emulator name’, appium server would launch the desired avd for you. However, I had trouble launching the emulator, where appium fails with an error saying that it was not able to find the desired emulator. I’ll try to describe my problem to the best of my understanding.

I generally try to launch an emulator by navigating into my “tools” directory and by issuing a command, something like
./emulator -avd NexusTest (I’m on Mac)
The emulator boots up and I start my test now, and appium would check if the app was already installed, if not install it, sign, etc…, everything works find, and I can proceed with my tests.

Now, while browsing through the appium documentation, I found a new desired capability (probably it was existing much before, but I came to know about it very late), avd, which when set would launch the desired emulator for you. So I use the new capability and pass it to appium, something like desiredCapabilities.setCapability(“avd”, “NexusTest”); (I use Java). This makes appium actually launch the emulator, and it boots up. However, after trying for some time ( it passes a telnet command to get the avd name, and here it fails, I believe) ultimately it fails with an exception saying the it could not find the desired emulator. At this point when I do an adb devices, I get a message saying that emulator-5554 is online (its avd name is NexusTest though). Im running Appium.app GUI application, and its on 1.4.13

The appium server log, at the time of error is below. At this point, the emulator is fully up and running, probably that’s why appium/adb devices say that 1 device was connected.

info: [debug] Trying to find NexusTest emulator

info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: /Users/plateau/Documents/R/android/platform-tools/adb devices

info: [debug] 1 device(s) connected
info: [debug] 1 emulator(s) connected
info: [debug] Sending telnet command to device: avd name
info: [debug] Getting running emulator port
info: [debug] Socket connection to device created
info: [debug] Socket connection to device ready

info: [debug] Telnet command got response: ae[Ke[Dave[Ke[De[Davde[Ke[De[De[Davd e[Ke[De[De[De[Davd ne[Ke[De[De[De[De[Davd nae[Ke[De[De[De[De[De[Davd name[Ke[De[De[De[De[De[De[Davd namee[K

NexusTest
info: [debug] Emulator NexusTest not running
info: [debug] Sent shutdown command, waiting for UiAutomator to stop…

warn: UiAutomator did not shut down fast enough, calling it gone

info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session

error: Failed to start an Appium session, err was: Error: Could not find NexusTest emulator.

info: [debug] Error: Could not find NexusTest emulator.
at [object Object].ADB.getRunningAVDWithRetry (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:715:15)
at [object Object]. (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:794:10)
at [object Object].ADB.checkSdkBinaryPresent (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:116:5)
at [object Object].ADB.launchAVD (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:760:8)
at [object Object]. (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:800:23)
at [object Object]. (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:720:11)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:707:9
at done (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/node_modules/async/lib/async.js:132:19)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/node_modules/async/lib/async.js:32:16
at [object Object]. (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:703:11)
at Socket. (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:1538:9)
at Socket.emit (events.js:107:17)
at TCP.close (net.js:485:12)

Is there anything which I am doing wrong?

Hi!

I’m having the same problem. Did you find out how to solve it?

1 Like

I’m having the same issue and I just found this post:

https://code.google.com/p/android/issues/detail?id=199435

It seems that the emulator has a different output, so, not much we can do…

Oh Ok, thanks for the info dalvarez, looks like it is not possible to launch avd through the desired capabilities, directly from appium. Currently the way I am doing it is, I will be manually launching an emulator before my test run and proceed from there. Let’s wait and see if anyone has a solution or a workaround.