5

I am implementing automation test cases for one application. I wanted to generalized some test cases in order to run on each and every device based on some condition. So, in order to do that I have to get device name using some code. I am not able to get code for checking device name. Any help is most welcome!!!

Kirti Parghi
  • 1,142
  • 3
  • 14
  • 31

5 Answers5

0

While setting appium capabilities, you must be setting device name as well. You can use the same one

Shrirang
  • 198
  • 1
  • 10
  • Thanks for your suggestion. Actually i know how to fetch device name using capabilities. My concern is when I am connecting my device with Appium. I need to check which device is connected right now. Because I want to run different test cases for different device. Can you help regarding it? – Kirti Parghi Jan 17 '19 at 18:07
  • where are you running these automated tests? On cloud platforms like sauce labs or on your local system? – Shrirang Jan 18 '19 at 05:00
0

Try session details to get connected device name or udid

 String connectedDeviceName = driver.getSessionDetail("deviceName").toString();
 String connectedDeviceUdid = driver.getSessionDetail("deviceUDID").toString();
Amit Jain
  • 4,389
  • 2
  • 18
  • 21
  • AndroidDriver class constructor requires capabilities as a parameter, so in that capability object we have to mentioned everything regarding device. I don't want it. At the starting of running test cases I want to check which device is connected. I have 2 test case out of which one test case should be run on first device and second test case should be run on second device. – Kirti Parghi Jan 17 '19 at 21:03
0

What you can do is use multiple devices to run automation tests on, in that way you can give a specific device udid to a specific class containing your test cases and those test cases will run on only that device.

Moreover, you can use Annotations using TestNG e.g @Beforesuite. This will run a specific class only, so only a limited test cases will run.

Nauman Malik
  • 188
  • 8
0

You can use any of the following methods to get device udid. All the following method will give the same output.

driver.getSessionDetail("deviceName");
driver.getSessionDetail("udid");
driver.getSessionDetail("deviceUDID");
driver.getCapabilities().getCapability("deviceName");
driver.getCapabilities().getCapability("udid");
driver.getCapabilities().getCapability("deviceUDID");

You can use device udid instead of device name

Suban Dhyako
  • 2,436
  • 4
  • 16
  • 38
0

[Solution Works only on Android devices]In Order to identify your devices connected to the system ,

adb devices

it will give list of devices connected at present time. [Implementation]

  1. Build a queue with device name.
  2. Do ADB devices and get the result into your queue(Device name would appear).
  3. Based on your condition run the test cases as you stated above.