Nafeez Quraishi
Nafeez Quraishi

Reputation: 6178

How to run a test which needs two devices using Appium

I understand that in order to control multiple devices using Appium i need to start multiple Appium servers with different ports. But, i am unable to get how can i target part of my tests to a specific device when multiple devices are connected to host computer.

I understand, below are the two configurations i need to do in order to handle multiple devices connected to a computer.

  1. port setting: e.g. 4723 in below webdriver initialization

    webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps_first_device)

  2. desired_caps for different devices.e.g.

    desired_caps_first_device = {'platformName': 'Android', 'platformVersion': '7.0', 'deviceName': 'gts210velte', 'appPackage':'package_name', 'appActivity':'activity_name'}

I have two Android devices are connected to a machine and both are of same model(deviceName). I understand that i can create two driver instances but how would Appium know which instance is for which physical device? In other words how should i differentiate between the two devices in the code so that i know a piece of code is going to be executed on a particular device out of the two connected to a machine?

Upvotes: 1

Views: 1806

Answers (3)

pankaj mishra
pankaj mishra

Reputation: 2615

Two similar kind of devices are distinguished by udid.

Here is a sample script to make connection with 1 device, you can have a look on this and modify it to suite ur needs for multiple devices.

Example is self explanatory.

https://automationlab0000.wordpress.com/2018/08/21/first-automation-script-using-robot-framework/

Upvotes: 0

Nafeez Quraishi
Nafeez Quraishi

Reputation: 6178

I found that there is a property called udid which can be assigned adb device id to target specific android device when multiple devices are connected to host machine.

e.g.

device_caps_first_device =  {'platformName': 'Android', 'platformVersion': '7.0', 'udid': 'xxxxxxx', 'deviceName': 'gts210velte', 'appPackage':'package_name', 'appActivity':'activity_name'}

device_caps_second_device =  {'platformName': 'Android', 'platformVersion': '7.0', 'udid': 'yyyyyyy', 'deviceName': 'gts210velte', 'appPackage':'package_name', 'appActivity':'activity_name'}

udid is defined as Unique device identifier of the connected physical device at http://appium.io/docs/en/writing-running-appium/caps/

Upvotes: 1

Wasiq Bhamla
Wasiq Bhamla

Reputation: 959

Use the desired capability of udid with the ID of the device you need to map to whichever server you like.

The ID for the device can be found using the following command:

$ adb devices

Upvotes: 3

Related Questions