简体   繁体   English

Appium:如何使用java中的自动化测试用例检查设备名称

[英]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. 设置appium功能时,您还必须设置设备名称。 You can use the same one 你可以使用同一个

Try session details to get connected device name or udid 尝试会话详细信息以获取连接的设备nameudid

 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. 您可以使用多个设备来运行自动化测试,这样您就可以将特定设备udid提供给包含测试用例的特定类,并且这些测试用例仅在该设备上运行。

Moreover, you can use Annotations using TestNG eg @Beforesuite. 此外,您可以使用TestNG使用注释,例如@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 . 您可以使用以下任何方法来获取设备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 您可以使用设备udid而不是设备名称

[Solution Works only on Android devices]In Order to identify your devices connected to the system, [解决方案仅适用于 Android 设备]为了识别您连接到系统的设备,

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).执行 ADB devices 并将结果放入您的队列(将出现设备名称)。
  3. Based on your condition run the test cases as you stated above.根据您的情况运行上述测试用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Java实现Appium自动化 - appium automation using java 使用Appium和Java进行移动测试自动化时,不会发生此类元素问题 - No such element issue occurring on mobile test automation using Appium and Java 如何在appium中打开和访问导航侧抽屉? 我正在使用Java语言在Appium中实现自动化 - How to open & access navigation side drawer in appium ? I am using java language for automation in appium 将Java测试自动化与Microsoft Test Manager,TFS和测试用例链接 - Linking Java Test Automation with Microsoft Test Manager, TFS , Test Cases 如何使用Java for iPhone Automation在MAC上设置Appium? - How to setup Appium on MAC with Java for iPhone Automation? 如何在 Java appium 自动化中处理警报或弹出窗口 - How to handle alert or popup in Java appium automation 如何使用Appium驱动程序获取设备名称和应用程序版本 - How to get Device name and App Version using Appium Driver Appium:启动Java测试用例时出现Maven问题 - Appium: Issue with maven while launching java test cases Appium-如何使用Java从iOS设备读取日志 - Appium - How to read log from iOS device using java 如何使用appium在移动应用程序中有效地划分测试用例以使其自动化 - How to divide test cases effectively to automate them in a mobile app using appium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM