Overview
This guide provides step-by-step instructions to run mobile automation tests in parallel using two Android emulators with Appium and WebdriverIO (WDIO). By setting up two emulators and configuring independent Appium instances, testers can execute multiple test flows simultaneously, significantly improving execution speed and test coverage.
Introduction
Parallel testing in Appium enables the execution of multiple test scenarios at the same time across different devices or emulators. This approach is especially beneficial for automation suites where sequential test runs are time-consuming.
Pre-Requisites:
- Set the laptop’s Power Mode to Performance (or Best Performance).
- Ensure the laptop charger is plugged in.
- Close all unnecessary applications and browser tabs (especially unused Chrome tabs).
- Create 2 emulators in Android Studio, each with:
- 3GB RAM
- 2 CPU cores (do not assign more than 2)
- You can configure these settings while creating or editing the AVDs in Android Studio.
Steps for Running 2 Emulators in Parallel:
1. Open 3 Terminals and run the following:
Terminal 1:
1. adb kill-server //kills any existing ADB server.
2. ps aux | grep appium | grep -v grep //Checks if any Appium servers are currently running.
3. pkill -f appium //Run this twice or thrice to stop all running Appium server processes.
Run the second command again to verify no Appium servers are running.
4. adb start-server //Starts the ADB server again.
Terminal 2:
emulator -avd <First emulator name> -port 5554 //Enter your First emulator name
Wait for the emulator to boot and stabilize.
Terminal 3:
emulator -avd <Second emulator name> -port 5556 //Enter your Second emulator name
Wait for the emulator to boot and stabilize.
To confirm both emulators are running, Open a New terminal and run:
adb devices
Output should be:
List of devices attached
emulator-5554 device
emulator-5556 device
Keep all 3 terminals running.
2. WDIO Configuration in VS Code:
Navigate to wdio.conf.js → Modify the config file with below configurations
const { resolve } = require('path');
exports.config = {
runner: 'local',
path: '/',
maxInstances: 2, // Number of Emulators running
exclude: [],
capabilities: [
{
platformName: 'Android',
'appium:deviceName': 'Pixel_6_Pro', //First Emulator
'appium:udid': 'emulator-5554',
'appium:automationName': 'UiAutomator2',
'appium:app': resolve(__dirname, 'android/app/app-qa-release.apk'), //Yor app package path
'specs': ['./UI_testing/UI_testing_1/Flow_1/*.feature'], //Path of the feature file which needs to be run in first emulator
'appium:systemPort': 8200,
'appium:chromeDriverPort': 8000,
'appium:mjpegServerPort': 9100,
'appium:adbExecTimeout': 120000,
'appium:uiautomator2ServerInstallTimeout': 120000,
'appium:uiautomator2ServerLaunchTimeout': 120000,
'appium:androidInstallTimeout': 600000,
'appium:newCommandTimeout': 600000,
'appium:autoGrantPermissions': true,
'appium:autoDismissAlerts': true,
'appium:skipUnlock': true,
'appium:noReset': false,
'appium:fullReset': false
},
{
platformName: 'Android',
'appium:deviceName': 'Pixel_6',
'appium:udid': 'emulator-5556',
'appium:automationName': 'UiAutomator2',
'appium:app': resolve(__dirname, 'android/app/app-qa-release.apk'),
'specs': ['./UI_testing/UI_testing_1/Flow_2/*.feature'], //Path of the feature file which needs to be run in second emulator
'appium:systemPort': 8201,
'appium:chromeDriverPort': 8001,
'appium:mjpegServerPort': 9101,
'appium:adbExecTimeout': 120000,
'appium:uiautomator2ServerInstallTimeout': 120000,
'appium:uiautomator2ServerLaunchTimeout': 120000,
'appium:androidInstallTimeout': 600000,
'appium:newCommandTimeout': 600000,
'appium:autoGrantPermissions': true,
'appium:autoDismissAlerts': true,
'appium:skipUnlock': true,
'appium:noReset': false,
'appium:fullReset': false
}
],
logLevel: 'warn',
framework: 'cucumber',
cucumberOpts: {
require: ['./UI_testing/step-definitions/*.js'],
timeout: 900000,
format: [`json:reports/cucumber-report-${Date.now()}.json`]
},
reporters: ['spec'],
services: [
['appium', {
args: {
relaxedSecurity: true,
allowInsecure: 'adb_shell',
port: 4723,
bootstrapPort: 4724,
chromedriverPort: 8000,
sessionOverride: true,
debugLogSpacing: true
},
logPath: './logs/'
}],
['appium', {
args: {
relaxedSecurity: true,
allowInsecure: 'adb_shell',
port: 4725,
bootstrapPort: 4726,
chromedriverPort: 8001,
sessionOverride: true,
debugLogSpacing: true
},
logPath: './logs/'
}]
],
before: async function (capabilities, specs) {
console.log(`Starting test on device: ${capabilities['appium:deviceName']}`);
await browser.pause(2000);
},
afterTest: async function (test, context, { error }) {
if (error) {
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const screenshotPath = `./errorShots/${this.capabilities['appium:deviceName']}_${timestamp}.png`;
await browser.saveScreenshot(screenshotPath);
}
},
onPrepare: function () {
require('fs').mkdirSync('./reports', { recursive: true });
require('fs').mkdirSync('./logs', { recursive: true });
}
};
3. Running the Tests:
After the configuration setup is complete, go to VS Code Terminal and run:
npx wdio wdio.conf.js
This will execute the test in both emulators in parallel.
This is exactly how the test runs in parallel.
Key Benefits of Running Parallel Tests Using Two Emulators:
- Running tests concurrently on two emulators cuts total testing time roughly in half compared to sequential runs.
- Enables simultaneous execution of different test flows or feature sets, improving overall test coverage within the same time frame.
- Helps simulate real-world usage by running distinct test cases or configurations on separate emulators concurrently.
- Running tests on multiple device configurations in parallel helps catch compatibility issues sooner.
- Easier to scale test automation for bigger projects by adding more emulator instances and distributing tests across them. (Depending on RAM Size of the Laptop)
Troubleshooting
If you encounter Logcat issue, check for uiautomator updates.
appium driver update uiautomator2
This will update the uiautomator if new update is available.
If you encounter issue like:
Appium Settings app is not installed
io.appium.settings not found
Wipe out the emulator’s data
emulator -avd <your_emulator_name> -wipe-data
This will re-boot the emulator and the issue will be fixed.
If you find any server related issues, Open a New Terminal and run :
1. adb kill-server
2. adb start-server
