Reputation: 839
I have 5 mobile devices and I want to run my automated mobile app tests cases on all the devices for checking the compatibility. For this, I need to run each test on all 5 devices simultaneously. So if I have 10 test cases, each will run on all devices which will make the total count 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. I understand that multiple Appium sessions are to be created for this. 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. Now I want test1() to be run on each device. Similarly, it applies to test2(). I can create multiple Appium session and assign a device from the device pool. The problem is how to duplicate test methods on the runtime in TestNG.
I couldn't find any straightforward way of doing this in TestNG. Is it possible to achieve? If yes, any example would work.
Upvotes: 1
Views: 1369
Reputation: 417
If you are using maven and TestNG - then you should know about .xml files with suite of tests. Try to implement IAlterSuiteListener and alter your .xml with tests file. Test NG allows separating threads in various ways: for example for 3 devices you can run 1 same test in such way:
thread-count
and add Tests in loop.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
Upvotes: 0
Reputation: 246
You have to initiate multiple appium session for each device. Also, follow the following link to proceed with things in details.
https://www.toolsqa.com/mobile-automation/appium/appium-parallel-execution-using-testng/
Upvotes: 0