0

I have configured two android device in my machine. One is real android device (ZX1D63R33N)[Moto G Second Gen - With 5.0.2 - API 21] and GenyMotion android emulator [With 5.1.1 with API 22].

Script get executed in both device successfully. But i'm not able to control the execution in which device i should perform the execution.

Consider I connect my real android device first and start the Genymotion emulator second. then adb device will give the following output.

C:\Users\Ramkumar>adb devices
List of devices attached
ZX1D63R33N      device
192.168.56.101:5555     device 

I have set the following SelendoidCapabilities in my script.

    WebDriver driver;   //AppiumDriver driver

    //new SelendroidCapabilities.
    SelendroidCapabilities selendroidCapabilities = SelendroidCapabilities.emulator(DeviceTargetPlatform.ANDROID22, "Android Emulator");
    selendroidCapabilities.setEmulator(true);
    selendroidCapabilities.setCapability("browserName", "Chrome");
    selendroidCapabilities.setCapability("device", "Android");
    selendroidCapabilities.setCapability("version", "5.1");
    selendroidCapabilities.setCapability("deviceName", "192.168.56.101:5555");
    selendroidCapabilities.setCapability("platformName", "Android");

    //capabilities.setCapability("app", app.getAbsolutePath());
    //capabilities.setCapability("appPackage","com.android.chrome");
    driver = new SelendroidDriver(new URL("http://localhost:4723/wd/hub"), selendroidCapabilities);
    driver.get("https:google.com");
    Thread.sleep(20000);
    driver.quit();

When i execute the script, its getting executed in the phone.It opens as chrome browser and open google page. No matter I have set emulator as true and created a SelendroidCapabilities with emualtor as option.

Even when i close my GenyMotion emualtor and have real android device connected and adb device command also show only one real device connected. Then too i see its getting executed in the real android device

C:\Users\Ramkumar>adb devices
List of devices attached
ZX1D63R33N      device

Vice versa also same issue. if i start a real device first and GenyMotion emualtor second, then adb device command gives output as

C:\Users\Ramkumar>adb devices
List of devices attached
ZX1D63R33N      device
192.168.56.101:5555     device

Having following SelendroidCapabilities is not running the script on real android device but on the GenyMotion emualtor.

    SelendroidCapabilities selendroidCapabilities = SelendroidCapabilities.device(DeviceTargetPlatform.ANDROID22, "Android Emulator");
    selendroidCapabilities.setEmulator(false);

Kindly suggest if i'm missing any configuration. Thanks in advance.

Regards, Ramkumar

Ramkumar
  • 116
  • 1
  • 11

2 Answers2

0
    1. Use this: SelendroidCapabilities caps = new SelendroidCapabilities(); 
        in place of this:    
     SelendroidCapabilities selendroidCapabilities = SelendroidCapabilities.emulator(DeviceTargetPlatform.ANDROID22, "Android Emulator");

    2. Use capability caps.setSerial(deviceId) 
        in place of 
      selendroidCapabilities.setCapability("deviceName", "192.168.56.101:5555"); 

deviceId is the same device serial number which you get on executing adb devices, this output you can pass to control where you have to execute test.

Pankaj Kumar Katiyar
  • 1,474
  • 1
  • 20
  • 36
  • Thanks for your reply, I tried the same you have mentioned, but still it picks always the first devices coming from adb devices command. – Ramkumar Mar 16 '16 at 09:53
  • ' SelendroidCapabilities selendroidCapabilities = new SelendroidCapabilities(); selendroidCapabilities.setSerial("192.168.56.101:5555"); selendroidCapabilities.setCapability("version", "5.1"); selendroidCapabilities.setCapability("deviceName", "192.168.56.101:5555"); selendroidCapabilities.setCapability("browserName", "chrome")' – Ramkumar Mar 16 '16 at 09:56
  • Below is the logs in node appium.js info: [debug] Trying to find a connected android device info: [debug] Getting connected devices... info: [debug] executing cmd: C:\Users\Ramkumar\AppData\Local\Android\android-sdk\platform-tools\adb.exe devices **info: [debug] 2 device(s) connected info: Found device ZX1D63R33N info: [debug] Setting device id to ZX1D63R33N** – Ramkumar Mar 16 '16 at 09:57
  • Same case if emulator is opened first.... info: [debug] Trying to find a connected android device info: [debug] Getting connected devices... info: [debug] executing cmd: C:\Users\sg0210523\AppData\Local\Android\android-sdk\platform-tools\adb.exe devices **info: [debug] 2 device(s) connected info: Found device 192.168.56.101:5555 info: [debug] Setting device id to 192.168.56.101:5555** – Ramkumar Mar 16 '16 at 09:59
  • selendroid will always pickup the first device coming from command adb devices, so if you want to execute on both, you need to put a loop and in that complete test on first device and then on second !! Is it you are trying to do or something else ? – Pankaj Kumar Katiyar Mar 16 '16 at 10:18
  • No, i want to run few test case in real device and few in emulator, Test case data specify if its device or emulator... – Ramkumar Mar 16 '16 at 10:30
  • Based on the condition which decides the test to be run on device / emulator, you can use that and pass it as deviceID this way you can control your test. – Pankaj Kumar Katiyar Mar 16 '16 at 10:34
  • Thanks @Pankaj for your replies – Ramkumar Mar 16 '16 at 11:41
0

Well finally, i was able to perform a device specific run. Only thing I was missing in my old code i was setting my device to deviceName property and not udid.

C:\Users\Ramkumar>adb devices
List of devices attached
192.168.56.101:5555     device
ZX1D63R33N      device

For this, i have to set the serial number with udid.

    capabilities.setCapability("version", "5.1");
    capabilities.setCapability("deviceName", "SomethingDoesntMatter");
    capabilities.setCapability("browserName", "chrome");
    capabilities.setCapability("device", "Android");
    capabilities.setCapability("udid","ZX1D63R33N");   // 192.168.56.101:5555   // ZX1D63R33N
    capabilities.setCapability("platform", "Android");

capabilities.setCapability("udid","ZX1D63R33N"); - This is the property which set the device id. When i set the value to ZX1D63R33N, it run on my real android device, and when set to 192.168.56.101:5555 it executes on emulator.

When deviceName was a mandatory, I tried to set the serial number with that value. It doesn't matter what value we set in deviceName

Thanks!

Ramkumar
  • 116
  • 1
  • 11