# Running Tests in Parallel on Multiple Devices

# Introduction

  • If you need to run a large number test-cases, running them consecutively can take a long time. In order to save time and avoid wasting CPU power, you can run them in parallel.

  • There are four basic ways of running multiple Appium sessions:

    • Run multiple Appium servers, and one session resides on each server
    • Run one Appium server, and multiple sessions reside on it
    • Run one or more Appium servers behind a Selenium Grid Hub, and sessions all reside on the Grid Hub
    • Use a cloud provider (which runs many Appium servers, most likely behind a single gateway).
  • This tutorial will guide you through running tests in parallel on a single Appium server (the second option).

Note

The number of concurrent tests you can run is the based on the number of agents you've purchased.

Note

When the client starts running test suites or test cases, each one creates a session to tell the Appium server which driver to use to connect to the platform. Quick map running mobile testing reference

# Parallel Testing Configuration

Warning

Currently you cannot run parallel Safari/Webview sessions due to an bug in iOS reference.

# Parallel Testing Capabilities

# Common Properties For Android and iOS

  • udid: The device's id. If it is not specified, the first available device/emulator will be used. This means that some sessions may target the same device when the user wants them to run separately on multiple devices. For running tests in parallel, it's essential to use the udid capability even with emulators unless you've specified both the deviceName and platformVersion(see below).
  • deviceName and platformVersion: When you specify a unique combination of deviceName and platformVersion Appium will find the device and you don't need to specify the udid.

# Specific Properties for Android

  • systemPort: Appium uses an HTTP connection to connect to the UiAutomator2 process. The port on the server system can only be used for one session at a time. When you're running multiple sessions with a single server, you'll need to specify the port using this field (8200 for one and 8201 for another).

  • chromeDriverPort: If you're testing webviews or using Chrome , Chromedriver also requires a unique port for each session.

example for android:

{
          "browser": "android-emulator",
          "app": "path to CarRental.apk",
          "desiredCapabilities": {
            "platformName": "android",
            "deviceName": "emulator",
            "udid": "emulator-5554",
            "automationName": "UiAutomator2",
            "newCommandTimeout": 600,
            "systemPort":8201
          }
        }

# Specific Properties for iOS

  • wdaLocalPort: iOS XCUITest driver also uses a specific port when communicating with the WebDriverAgent on the iOS device. You should also make sure these are unique.

  • webkitDebugProxyPort: ios-webkit-debug is a service that manages connections on a specific port when testing Webviews and/or Safari with Appium. Again, make sure these ports are unique.

example for iOS:

{
          "browser": "iPhone Xs",
          "app": "path to file CarRental.ipa",
          "desiredCapabilities": {
            "platformName": "iOS",
            "platformVersion": "13.1",
            "deviceName": "iPhone  11 Pro Max",
            "udid": "unique id for devices/ simulator",
            "automationName": "XCUITest",
            "connectHardwareKeyboard": false,
            "newCommandTimeout": 600,
            "wdaLocalPort":8206
          }
        }

# Putting all capabilities into JSON file.

  • When running parallel tests, we need to declare the run mode 'multiple' with various browsers in file gondola.json using following format:
"multiple": {
    "test-name-userInput": {
      "outputName": "",
      "browsers": [ {"cap1":"desiredCap1"} , {"cap2":"desiredCap2"} ]
    }
  }

full example file gondola.json for parallel running

{
  "output": "./results",
  "helpers": {
    "Appium": {
      "require": "./node_modules/@logigear/gondola/built/helper/AppiumEx",
      "smartWait": 5000,
      "app": "/Volumes/DATA/Projects/Test/CarRental/AUT/CarRental.apk",
        "desiredCapabilities": {
          "platformName": "android",
          "deviceName": "emulator"
        }
    },
    "GondolaHelper": {
      "require": "./node_modules/@logigear/gondola/built/helper/gondolahelper"
    }
  },
  "plugins": {
    "screenshotOnFail": {
      "enabled": "true"
    },
    "allure": {
      "enabled": "true"
    }
  },
  "tests": "./built/tests/*.js",
  "name": "SampleAndroidandiOS",
  "multiple": {
    "login": {
      "outputName": "login",
      "browsers": [
        {
          "browser": "iPhone 8",
          // set "app" to the absolute path of your ipa file.
          "app": "/Volumes/DATA/Projects/Test/CarRental/AUT/CarRental.ipa",
          "desiredCapabilities": {
            "automationName": "XCUITest",
            "platformName": "iOS",
            "platformVersion": "12.0",
            "deviceName": "iPhone 8",
            "connectHardwareKeyboard": false
          }
        },
        {
          "browser": "android-emulator",
          // set "app" to the absolute path of your apk file.
          "app": "/Volumes/DATA/Projects/Test/CarRental/AUT/CarRental.apk",
          "desiredCapabilities": {
            "platformName": "android",
            "deviceName": "emulator",
            "automationName": "UiAutomator2",
            "newCommandTimeout": 600
          }
        }
      ]
    }
  }
}

# Running The Tests

  • We use '--all' to tell @logigear/gondola to run all of the suites on each of the available devices. You can add this after the gondola run command in the script section of the file packages.json or call the command directly like below:
./node_modules/.bin/gondola -c gondola.multi.json run-multiple --steps --all
Last Updated: 2/2/2021, 6:54:30 AM