'Appium : how to check device name using automation test cases in java
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!!!
Solution 1:[1]
While setting appium capabilities, you must be setting device name as well. You can use the same one
Solution 2:[2]
Try session details to get connected device name or udid
String connectedDeviceName = driver.getSessionDetail("deviceName").toString();
String connectedDeviceUdid = driver.getSessionDetail("deviceUDID").toString();
Solution 3:[3]
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.
Solution 4:[4]
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
Solution 5:[5]
[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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shrirang |
| Solution 2 | Amit Jain |
| Solution 3 | |
| Solution 4 | Suban Dhyako |
| Solution 5 | Snehal Gajbhiye |
