How to run same testcase parallel on iOS and Android

Hi,

How can i run same Test case parallel on iOS and Android device. is that possible?

Could some one help on this.

Thanks in advance.

@sudhakar

You can run the same test case in parallel but there are a few things you need to take into consideration:

  1. iOS and Android apps are built differently. Identification methods (i.e. Xpath) that will work for one, will not work for the other.
  2. It’s not possible to run parallel test using only Appium Studio. For this purpose you will have to use an IDE and unit testing in order to run these tests in parallel. I recommend using TestNG.
  3. You will be creating two separate test classes that embody the same test case. TestNG will let you run these test classes in parallel, effectively allowing you to achieve your goals.

Thanks nivi,

for great solution.

I am using Eclipse with Testng.

Could you please share any snippet which you have that works.

That would be appreciated.

Thanks in Advance

Hi @sudhakar

Let’s assume that your test classes are named:
AndroidDemoTest.java
And
IOSDemoTest.java

Your testng.xml should look like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests">
  <test name="TestIOS">
  	<parameter name="deviceQuery" value="@os='ios'"/>
    <classes>
      <class name="IOSDemoTest"/>
    </classes>
  </test> <!-- Test -->
  <test name="TestAndroid">
  	<parameter name="deviceQuery" value="@os='android'"/>
    <classes>
      <class name="AndroidDemoTest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

If you want a dry run (without actually running any tests on devices), you can run the following classes:

Android:

public class AndroidDemoTest {
	protected AndroidDriver<AndroidElement> driver = null;
	
	@BeforeMethod
	@Parameters("deviceQuery")
	public void setUp(@Optional("@os='android'") String deviceQuery) throws Exception{
		System.out.println("Before: " + deviceQuery);
	}
	
	@Test
	public void test(){
		System.out.println("Running Android Test!");
	
	}
	
	@AfterMethod
	public void tearDown(){
		System.out.println("Quit!");
	}
}

iOS:

public class IOSDemoTest {
	protected IOSDriver<IOSElement> driver = null;

	@BeforeMethod
	@Parameters("deviceQuery")
	public void setUp(@Optional("@os='ios'") String deviceQuery) throws Exception{
		System.out.println("Before: " + deviceQuery);
	}
	
	@Test
	public void test(){
		System.out.println("Running iOS Test!");
	
	}
	
	@AfterMethod
	public void tearDown(){
		System.out.println("Quit!");
	}
}