'How to config multiple env files to run for multiple user roles in WebDriver IO?

I am using Webdriver IO Framework with Cucumber and Page Object Model. I am able to setup multiple env files and run tests again each environment and it works.

  ` "test:prod": "./node_modules/.bin/wdio wdio.prod.conf.js",
    "test:dev": "./node_modules/.bin/wdio wdio.dev.conf.js",
    "test:stage": "./node_modules/.bin/wdio wdio.stage.conf.js"`

However, I have to run test login for multiple roles i.e. Admin, User, QA etc in each environment. I have created test data files i.e. dev_login.json, stag_login.json, prod_login.json which contains different login details for each role.

Feature file looks like below

[ 
    {
        "userType" :"QA",
        "userName" : "Test",
        "password" : "test123"
    },
    {
        "userType" :"ADMIN",
        "userName" : "admin",
        "password" : "admin123"
    },
  Scenario: Valid Login
    Given I open a website
    When I login as 'ADMIN' user
    Then Page title 'Test' should be displayed
    
  Scenario: Valid Login
    Given I open a website
    When I login as 'QA' user
    Then Page title 'Test' should be displayed

Does anyone know how can I use Env specific json files along with wdio config files and write minimal code to get userType passed from FeatureFile and read the same type from json file and get login details before test run?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source