简体   繁体   中英

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

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

Try session details to get connected device name or udid

 String connectedDeviceName = driver.getSessionDetail("deviceName").toString();
 String connectedDeviceUdid = driver.getSessionDetail("deviceUDID").toString();

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 eg @Beforesuite. This will run a specific class only, so only a limited test cases will run.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM