How to make and run distributed tests in appium + node.js for Android

I am pleased to welcome you, my friend! Unfortunately, I have a problem that needs to be solved - this is very important for me and any information that will concern this topic for price! Thanks in advance!

I recently met UI testing. At the moment I have written a project that runs testing under the Android platform. Technology stack that I use: appium, nodejs, webdriverio.

This is my main file - index.js

const joinPath = require('./utils/utils').joinPath
const getDirContentRecursively = require('./utils/utils').getDirContentRecursively
const getFormattedDate = require('./utils/utils').getFormattedDate
const config = require('./config.json')


async function executeTests () {
  let args = process.argv
  if (!args.includes('android') && !args.includes('ios')) {
    await executeAndroid()
    await executeIos()
  if (args.includes('android')) await executeAndroid()
  if (args.includes('ios')) await executeIos()

async function executeAndroid () {
  console.log('Starting Android tests')
  let driver = getDriver(
  let tests = getTests(
  let reportDir = getReportDir(
  await executeTestsWithDriver(driver, tests, reportDir)

async function executeIos () {
  console.log('Starting iOS tests')
  let driver = getDriver(config.ios.capabilities)
  let tests = getTests(config.ios.testsDir)
  let reportDir = getReportDir(config.ios.reportsDir)
  await executeTestsWithDriver(driver, tests, reportDir)

function getDriver (caps) {
  const wdio = require('webdriverio')
  const driver = wdio.remote({
    protocol: config.appium.protocol,
    port: config.appium.port,
    path: '/wd/hub',
    deprecationWarnings: false,
    desiredCapabilities: caps
  return driver

function addAdditionalCommands (driver) {
  const commandsDir = config.directories.commands
  getDirContentRecursively(commandsDir, '.js').forEach(file => {
    const addCommand = require(file)

function getTests (platformTestsDir) {
  const tests = []

  getDirContentRecursively(config.directories.commonTests, '.js').forEach(filePath => tests.push(filePath))

  getDirContentRecursively(platformTestsDir, '.js').forEach(filePath => tests.push(filePath))
  return tests

function getReportDir (baseDir) {
  const date = getFormattedDate('dd-mm-yyyy_hh-MM-ss')
  return joinPath(__dirname, baseDir, date)

function executeTestsWithDriver (driver, tests, reportDir) {
  const runner = getTestRunner(reportDir)

  tests.forEach(path => {
    delete require.cache[path]

  global.reportDir = reportDir
  global.driver = driver
  global.account = require('./accounts/accounts.json')
  global.android_emulator = require('./emulators/android_emulators.json')

  return new Promise(resolve =>

function getTestRunner (reportDir) {
  const Mocha = require('mocha')
  const runner = new Mocha()

  runner.reporter('mochawesome', {
    'reportTitle': 'Integration Test',
    'reportPageTitle': 'Integration Test',
    'reportDir': reportDir,
    'saveJson': true,
    'reportFilename': 'report'
  return runner


  "name": "MyTesting",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "node index.js"
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "dateformat": "^3.0.3",
    "eslint": "^5.7.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-node": "^7.0.1",
    "eslint-plugin-promise": "^4.0.1",
    "eslint-plugin-standard": "^4.0.0",
    "mkdirp": "^0.5.1",
    "mocha": "^5.2.0",
    "mocha-parallel-tests": "^2.0.5",
    "mochawesome": "^3.1.1",
    "node-fetch": "^2.2.0",
    "uuid": "^3.3.2",
    "webdriverio": "^4.14.0"
  "dependencies": {}

The tests run and work very well, but I have another task.

It is necessary to start testing in such a way that some part of the tests are performed on one device, and another part is appropriate on another device. If I’m not mistaken, then this is called “distributed tests.”

The scheme of such testing:

  • When test #1 is launched, it starts working on one device.
  • Behind him runs the test #2., but on another device.
  • When test # 1 is completed, the next test is taken, if it is not started, test # 3 is launched, otherwise the next one.
  • etc.

Unfortunately, I do not understand how it is possible to achieve a solution to this problem within the framework of the used technology stack, which I described above. Perhaps there is a source of information that I could not find … I really need your help on how to release the launch of distributed tests in the appium and node.js… Thanks in advance!