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
  • 887
  • 2
  • 11
  • 27

4 Answers4

0

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

Shrirang
  • 198
  • 9
  • 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
  • 3,216
  • 2
  • 15
  • 20
  • 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
  • 178
  • 6
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
  • 1,970
  • 1
  • 11
  • 30