Android Parallel Automation

0.00 avg. rating (0% score) - 0 votes

Android Parallel Automation to increase Coverage

Naukri has more than a lakh users using its Android application. These users are widely spread across multiple android devices with various combinations of android versions. We work hard to ensure that our application works well for our entire user base. Acknowledging that appium scripts are slow, it was a time taking task to execute a 10 hours long script on multiple devices, calculatedly taking around half a day in execution on single device and completely taking around two to three days on just 3 devices (in the best possible scenario). If this round of testing has to go through more than one round of regression testing then it is a lot of waiting for results.

We wanted and rather needed to have a way where we could attain maximum coverage in least possible time, so as to ensure the thoroughness of our mobile application on various devices. Parallel automation was one solution which could help us achieve this. But, parallel automation came with its own set of challenges.

We found ways where we could distribute our complete script on multiple devices so as to reduce the time of execution of script. But, this didn’t give clear and device specific reports. Execution on different devices was clubbed into a single report, which made failure case identification difficult.

Another way which ensured coverage along with device wise reporting with least modification in our current framework was to execute complete script on different devices altogether at one go.

We choose to take the later approach to achieve our goal. Jenkins helped us to accomplish this task in a much smoother manner. Let’s go through the steps:

1. Create a node which can execute more than 1 job at a time
[Example: # of executors  – 2]

Android Jenkins Node

2. Create a Jenkins job which triggers multiple child jobs
– parentJob

Jenkins parent job

3. Create 2 Jenkins child jobs accepting parameters UDID and Port Number respectively       [for execution on 2 devices] (change number of child jobs as per your requirement)
udid: Device Id
port: Port where you want to start the Appium server

– childJob01
– childJob02

Jenkins child Job for one device

Jenkins child job for two device

4. Each child job will start appium server and execute the test suite for the provided device      (UDID and port number)

Android parallel automation

And thus, by triggering multiple child jobs at the same time using parent job we can execute entire suite parallel on various devices.

For clear functioning of code keep reading…..

What exactly is happening inside the code and how this takes place?

We pass these vales as parameters and we set these parameters to the “” file. Ultimately, methods to start Appium and start driver reads these config values and continues the execution.

startDriver ensures that 2 appium servers are started (one server for individual device)

startDriver code:

public AndroidDriver StartDriverAndroidApp(String appLocation, String appPackage, String appActivity) throws MalformedURLException{

	try {
	} catch (IOException | InterruptedException e) {

	try{Thread.sleep(5000);}catch(Exception e){}

	DesiredCapabilities capabilities = new DesiredCapabilities();	

        ThreadLocal<AndroidDriver> threadDriver = new ThreadLocal<AndroidDriver>();
	capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.3");
	capabilities.setCapability("udid", getPropertyValue("udid"));

	capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
	capabilities.setCapability(MobileCapabilityType.APP, appLocation);
	capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, appPackage);
	capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, appActivity);
	capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120);

	driver = new AndroidDriver(new URL(""+getPropertyValue("port")+"/wd/hub"), capabilities);

	System.out.println("========driver after launching app======== \n" + driver );
	driver.manage().timeouts().implicitlyWait(60000, TimeUnit.MILLISECONDS);
	System.out.println("==========complete launchApp========");
	return driver;

public void startAppiumServer() throws IOException, InterruptedException {   

	CommandLine command = new CommandLine("cmd"); 
	command.addArgument("--address", false);  
	command.addArgument("--port", false);  
	//command.addArgument("4723");   //before parallel execution implementation
	command.addArgument("--full-reset", false);
	command.addArgument("--command-timeout", false);
	command.addArgument("--full-reset", false);  

	DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();  
	DefaultExecutor executor = new DefaultExecutor();  
	executor.execute(command, resultHandler);  
	System.out.println("------------>>> Appium server started");  

A task that took approximately 3 days before, now takes 12 hours only. This change was implemented in a very smooth and beautiful fashion. Hence, it did not require major changes at framework end and no changes were made at the code level at all.

I hope this will also help you to make your executions faster along with taking care of coverage on multiple android devices.

One thought on “Android Parallel Automation

Comments are closed.