0

I am using Appium to automate my UI tests on Android.

I have a physical device connected to my computer, and an emulator launched from Android Studio:

$ adb devices
List of devices attached
0831bd3b21320609    no permissions (My phiscal Nexus 5)
emulator-5554   device (My Emulated device)

When I launch Appium and run my tests it picks up my phisical device. Appium Logs:

[debug] [ADB] Running '/home/babken/android-sdk/platform-tools/adb' with args: ["-P",5037,"-s","0831bd3b21320609","wait-for-device"]
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 2 device(s) connected
...

The tests hang and I get an error because it connects to the wrong device.

I have this in my appium capabilities:

desired_caps = {
    'platformName': 'Android',
    'deviceName': 'Android Device',
    'autoGrantPermissions': True,
    'app': apk_location,
    'newCommandTimeout': 36000,
}

I know I can set the udid capability to emulator-5554 but the emulator's name can change.

As a workaround I can also plug off my Nexus or turn off usb debugging but that's not a solution for me.

Babken Vardanyan
  • 14,090
  • 13
  • 68
  • 87

1 Answers1

0

Have you tried with 'avd' capability?

Something like

desired_caps = {
    'platformName': 'Android',
    'deviceName': 'Android Emulator',
    'avd': 'emulator',
    'autoGrantPermissions': True,
    'app': apk_location,
    'newCommandTimeout': 36000,
}

At the website, they put as an example of: api19, so maybe you can specify your emulator API version instead of name. (I haven't tried but it might work) And also you should put in deviceName 'Android Emulator'

https://appium.io/docs/en/writing-running-appium/caps/

barbudito
  • 548
  • 1
  • 6
  • 16