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!!!
5 Answers
While setting appium capabilities, you must be setting device name as well. You can use the same one

- 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
Try session details to get connected device name
or udid
String connectedDeviceName = driver.getSessionDetail("deviceName").toString();
String connectedDeviceUdid = driver.getSessionDetail("deviceUDID").toString();

- 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
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.

- 188
- 8
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

- 2,436
- 4
- 16
- 38
[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]
- Build a queue with device name.
- Do ADB devices and get the result into your queue(Device name would appear).
- Based on your condition run the test cases as you stated above.

- 64
- 4