2

I have multiple automation scripts setup with NodeJS, Protractor, Jasmine Framework and SauceLabs.

Each script is in separate .JS files and it reads data from .JSON files. I have defined login credentials and all other necessary data within the JSON files.

multiCapabilities: [{
    browserName: 'chrome',
    version: 'latest',
    platform: 'Windows 8',
    name: "tests",
    splitTestsBetweenCapabilities: true,
    acceptInsecureCerts: true,
    cssSelectorsEnabled: true,
    shardTestFiles: true,
    maxInstances: 5,
}],
maxSessions: 5,

Using this config, I am able to trigger 5 instances of Chrome browser and run 5 different scripts each fetching data on their own.

The problem is I need to use a rotating list of 20 login credentials for each script. I am not sure if there are any packages that do this already.

How should I approach this, so that each script can use one unique username and password? Each script should be able to pick a random credential and other scripts shouldn't able to use that until that script completes its' run.

Kowshika N
  • 23
  • 4
  • You need some sort of centralised storage. But why do you exactly need to rotate these logins? Why has a test to run with different logins each run? ? What's the reason behind this? Since protractor uses multiple processes it's hard to sync data between them (it's big efford for not much gain..) I don't understand why you have to rotate. – Silvan Bregy Jul 20 '21 at 14:59
  • 1
    I could think of to copy a file with all creds to a tmp dir. Then, in the tests, you access the file and consume one of the logins. When the test is done, it writes down the used login to file again. For synchronizing it maybe try this npm pacakage to lock it: => https://www.npmjs.com/package/lockfile , so lock the file when accessing it, and add a proper polling mechanism to your "readFile()" function in case it is locked at that moment! . I can give you an example if you want.,0 – Silvan Bregy Jul 21 '21 at 06:20
  • 1
    Another approach is to do it via `process.env` , but I guess `mutlipleinstances` will spawn different processes, so child processes cannot write to same `process.env` -- – Silvan Bregy Jul 21 '21 at 06:23

1 Answers1

1

You can use a separate process to update the data on the .json files and then trigger the scripts as you would normally.

There are npm packages like json-update available or you can build your own script to run before your script.

Naveen
  • 770
  • 10
  • 22