简体   繁体   English

如何使用 TestNG、Java 和 Appium 在多个移动设备上并行运行每个测试?

[英]How to run each tests on multiple mobile device in parallel using TestNG, Java and Appium?

I have 5 mobile devices and I want to run my automated mobile app tests cases on all the devices for checking the compatibility.我有 5 台移动设备,我想在所有设备上运行我的自动化移动应用测试用例以检查兼容性。 For this, I need to run each test on all 5 devices simultaneously.为此,我需要同时在所有 5 台设备上运行每个测试。 So if I have 10 test cases, each will run on all devices which will make the total count 50.因此,如果我有 10 个测试用例,每个测试用例都将在所有设备上运行,总计数为 50。

I am creating a device pool dynamically.我正在动态创建设备池。 The pool will have devices that are connected to the host machine.该池将具有连接到主机的设备。 So it will not have any prior idea of device UDID before running test cases.因此,在运行测试用例之前,它不会对设备 UDID 有任何事先了解。 I understand that multiple Appium sessions are to be created for this.我知道要为此创建多个 Appium 会话。 The problem is that I need to somehow create multiple copies of each test case depending on the number of devices connected and then run each of them on all the devices.问题是我需要根据连接的设备数量以某种方式创建每个测试用例的多个副本,然后在所有设备上运行每个测试用例。

Example:例子:

@Test
public void test1(){
}
@Test
public void test2(){
}

The device pool has 5 devices connected.设备池连接了 5 台设备。 Now I want test1() to be run on each device.现在我希望 test1() 在每台设备上运行。 Similarly, it applies to test2().同样,它适用于 test2()。 I can create multiple Appium session and assign a device from the device pool.我可以创建多个 Appium session 并从设备池中分配一个设备。 The problem is how to duplicate test methods on the runtime in TestNG.问题是如何在 TestNG 的运行时复制测试方法。

I couldn't find any straightforward way of doing this in TestNG.我在 TestNG 中找不到任何直接的方法。 Is it possible to achieve?有没有可能实现? If yes, any example would work.如果是,任何示例都可以。

You have to initiate multiple appium session for each device.您必须为每个设备启动多个 appium session。 Also, follow the following link to proceed with things in details.另外,请按照以下链接进行详细处理。

https://www.toolsqa.com/mobile-automation/appium/appium-parallel-execution-using-testng/ https://www.toolsqa.com/mobile-automation/appium/appium-parallel-execution-using-testng/

If you are using maven and TestNG - then you should know about.xml files with suite of tests.如果您使用的是 maven 和 TestNG - 那么您应该了解.xml 文件和测试套件。 Try to implement IAlterSuiteListener and alter your.xml with tests file.尝试实现IAlterSuiteListener并使用测试文件更改 your.xml。 Test NG allows separating threads in various ways: for example for 3 devices you can run 1 same test in such way: Test NG允许以各种方式分离线程:例如,对于 3 个设备,您可以通过以下方式运行 1 个相同的测试:

  1. Create TestNG.xml file with tests使用测试创建 TestNG.xml 文件
  2. Specify in this xml - listener that implements IAlterSuiteListener在此 xml 中指定 - 实现 IAlterSuiteListener 的侦听器
  3. Alter xml file in runtime with listener, that can detect number of connected devices (that equals thread number), so you can set thread-count and add Tests in loop.在运行时使用监听器更改 xml 文件,它可以检测连接设备的数量(等于线程数),因此您可以设置thread-count并在循环中添加测试。
suite name="Android Compatibility Tests" parallel="tests" thread-count="3"

<test name="Android Compatibility Test-1">
    <classes>
        <class name="tests.android_tests.AndroidCompatibilityTest">
        </class>
    </classes>
</test>

  <test name="Android Compatibility Test-2">
    <classes>
        <class name="tests.android_tests.AndroidCompatibilityTest">
        </class>
    </classes>
</test>

 <test name="Android Compatibility Test-3">
    <classes>
        <class name="tests.android_tests.AndroidCompatibilityTest">
        </class>
    </classes>
</test>

Read an documentation about parallelism in Appium 1 : https://www.javadoc.io/doc/org.testng/testng/6.11enter code here/org/testng/IAlterSuiteListener.html在 Appium 1中阅读有关并行性的文档https://www.javadoc.io/doc/org.testng/testng/6.11在此处输入代码/org/testng/IAlterSuiteListener.html

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

相关问题 在 Android 中使用 cucumber、appium 和 testNG 在 Java 中进行并行测试 - Parallel tests in Android with cucumber, appium and testNG in java 如何使用Eclipse并行运行TestNG测试? - How to run TestNG tests in parallel using Eclipse? Appium,Cucumber和Junit如何在多个设备上并行运行测试 - Appium, Cucumber and Junit how to run tests in parallel on multiple devices 如何使用数据提供程序在 testNG 上并行运行测试? - How to run tests in parallel on testNG using data provider? 使用 TestNG、Appium 和 Selenium 运行并行和顺序测试 - Running parallel and sequential tests using TestNG, Appium and Selenium 使用testng并行运行数据提供者测试 - Run data provider tests in parallel using testng 如何通过使用 TestNG 和 Selenium 的方法并行运行测试 - How to run tests in parallel by methods with TestNG and Selenium TestNG-如何在每次并行运行的类中的所有测试之前运行一次安装程序 - TestNG - How to run setup once before all tests in a class for each parallel run TestNG 使用 Java 使用来自同一个 ArrayList 的数据运行多个测试 - TestNG run multiple tests with data from same ArrayList using Java 与 Guice 和 TestNg 并行运行测试 - Run tests in parallel with Guice and TestNg
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM