Implementing Parallel Execution with Different Users Using WDIO and Appium

49 views Asked by At

I got a project using WDIO for mobile testing with appium and browserstack, I want to implement proper parallel execution, we got a couple of scenario that can be run in parallel but using different users. Explain this, I got a an spec file which needs to be run in 3 different devices, need to run in parallel but each instance needs to get a different user.

I got a list of users in a json file, like this

{
  "user1": {
    "email": "",
    "password": "",
    "beingUsed": false
  },
  "user2": {
    "email": "",
    "password": "",
    "beingUsed": false
  },
.....
}

I want that each thread pick a user from that list

I tried a couple of solutions but stay with this one

in each spec, using a before hook, lock the file, read the file, save an user and update the beingUsed flag, unlocked the file

  let userFinal
  let updatedUsers
  let loginFixtureFD;

  before(async function () {
    const fileUrl = new URL('../../support/fixtures/logintestparallel.json', import.meta.url)
    loginFixtureFD = openSync(fileUrl, 'r+');
    flockSync(loginFixtureFD, LOCK_EX);

    const loginFixtureData = exportJsonFile(fileUrl);
    for (const user in loginFixtureData) {
      if (Object.hasOwnProperty.call(loginFixture, user) && loginFixture[user].beingUsed === false) {
        loginFixtureData[user].beingUsed = true
        updatedUsers = JSON.stringify(loginFixtureData, null, 2)
        userFinal = loginFixtureData[user]
        break;
      }
    }
    writeFileSync(fileUrl, updatedUsers, 'utf8')
    flockSync(loginFixtureFD, LOCK_UN);
    closeSync(loginFixtureFD);

  })

this code does work, I mean it assigned the user, but seems like the 3 instances of the spec that WDIO spin up use the same execution, so they ended up using the same user, but if I setup 5 instances, which 3 run speca and 2 runs specb, the ones with specb will pick another user from the list.

but I need that the 3 from specA pick different users

in my config file for capabilities got this

 capabilities: [
    {
      'bstack:options': {
        deviceName: 'Google Pixel 7',
        platformVersion: '13.0',
        platformName: 'android',
        debug: true,
        networkLogs: true,
        appiumVersion: "2.0.1"
      },
      'appium:autoGrantPermissions': true,
      'appium:fullReset': true,
      "appium:autoWebView": true
    },
    {
      'bstack:options': {
        deviceName: 'OnePlus 9',
        platformVersion: '11.0',
        platformName: 'android',
        debug: true,
        networkLogs: true
      },
      'appium:autoGrantPermissions': true,
      'appium:fullReset': true
    },
    {
      'bstack:options': {
        deviceName: 'Samsung Galaxy Note 9',
        platformVersion: '8.1',
        platformName: 'android',
        debug: true,
        networkLogs: true
      },
      'appium:autoGrantPermissions': true,
      'appium:fullReset': true
    }
  ],
  maxInstances: 3,

have you done some similar to what i want to achieve? any recomendation?

0

There are 0 answers