Parallel Execution in Appium-Android Emulators and Real Devices


Parallel Execution in Appium-Android Emulators and Real Devices


As we all are aware parallel execution is one of the most important concepts in any of the test automation framework and by executing our test in parallel we can save a lot of time.

So in this Appium tutorial we would be looking into how we can execute Our Appium Test parallelly on Android Emulators.


Parallel execution of Tests on Android Emulators

In this example, we will try to execute one Sample test case in 2 Android emulators in parallel.

In order to achieve that we need to understand 2 important concepts:

A) We need to start/stop the Appium Server from Code:

Normally we use the Appium Desktop Application to start the Appium server and  one Appium the server is bound to one Appium Session (or you can say to one device/emulator), but now as we need to run the test case on 2 Android emulators at the same time, we need 2 Appium servers running on two different ports.


Now we can’t be dependent on the Appium Desktop Application as it will be able to run only one Appium Server. So the best approach would be to create and run 2 Appium servers at runtime using java and easily create the Runtime Appium Server by mentioning the particular port. 

In our case, we will need 2 different ports to start 2 different Appium Servers(or Sessions).

Below is the code which will start and stop the Appium server for port 4725.

B)   We need to use parameters in Test Class and testng.xml

We need to start 2 Appium Servers on 2 different ports and each device should be assigned to a single Appium Server.

This table may make it more clear:

S.No
Appium Port No
Device Name
Platform Version
1
4725
Emulator-9811
7.0
2
4726
Emulator-7811
8.0
                  
Now we need to pass these values from testng.xml to our Test Class before all initialization of the WebDriver takes place. And we will use the TestNG @Parameters annotation for that.




Please consider the below example to understand how @Parameter at the Test Class level and <parameter> at testng.xml level works.


If we want to run the test cases in parallel, then we need to use attributes along with the <suite> tag.

1) parallel: It has a number of possible values such as tests, classes, methods, and instances. If you want to run parallelization at <test> then you can use parallel="tests"

2) thread-count: No of threads to execute in parallel. If you want to execute 5 test cases in parallel then thread-count="2"

Below is the testing.xml file for execution
After adding this to testng.xml we just need to right-click on it and select Run option, and we will see the 2 Android emulators will open and each of them will execute test cases in parallel.

Parallel execution of Tests on Android Real Devices

Similarly, for executing parallel tests on real devices we need to pass the device name in testng.xml that we can get it using adb devices and execute our test in parallel on real devices.






SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post