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 iOS Simulators.
Parallel execution of Tests on iOS simulators
In this example, we will try to execute one Sample test case in 3 IOS Simulators (iPhone 6, iPhone 7 and iPhone 8) 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 server is bound to one Appium
Session (or you can say to one device/simulator), but now as we need to run the
test case on 3 iOS simulators at the same time, we need 3 Appium servers running
on three 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 3 Appium servers at runtime using java and easily create the Runtime Appium Server by mentioning the particular port.
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 3 Appium servers at runtime using java and easily create the Runtime Appium Server by mentioning the particular port.
In our case, we will need 3 different
ports to start 3 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
B) We need to use parameters in Test Class and testng.xml
We
need to start 3 Appium Servers on 3 different ports, and each device should be
assigned to a single Appium Server with a unique WDA port.
What is a WDA Port?
WDA port is used to forward traffic from the Mac host to the iOS Simulator to
real ios devices over USB.
This
table may make it more clear:
S.No
|
Appium Port
No
|
Device Name
|
WDA Port
|
1
|
4725
|
Iphone 6
|
8100
|
2
|
4726
|
Iphone 7
|
8200
|
3
|
4727
|
Iphone 8
|
8300
|
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 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, method
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="3"
After
adding this to testng.xml we just need to Right click on it and select Run option,
and we will see the 3 iOS Simulators will open and each of them will execute
test cases in parallel.
Below
is the testing,xml file for execution