We were facing a roadblock of running protractor tests on different environments using different configurations.
We tried different methods to fix this.
How we tackled this problem:
- We created empty parameters for each variable paramter in protractor.conf.js
params: {
baseUrl: “”,
url: “”,
user:””,
password:””,
Status:””,
}2. Protractor cli has support for running commands with parameters. For example We need to run tests on beta environment for some region with
admin credentials. We ran below command:protractor e2e/protractor.conf.js –params.baseUrl ‘preview’ –params.user ‘raj’ –params.password ‘test’ –params.Status ‘beta'”
As you can see that this command is pretty long and tough to remember we leveraged scripts functionality of npm.
3. We added scripts in package.json like below:
“scripts”: {
“beta-n”: “protractor e2e/protractor.conf.js –params.baseUrl ‘beta’ –params.user ‘anil’ –params.password ‘pass’ –params.Status ‘beta'”,
“beta-a”: “protractor e2e/protractor.conf.js –params.baseUrl ‘beta’ –params.user ‘raj’ –params.password ‘test’ –params.Status ‘beta'”}
4. In cli use below command to run tests on beta env with non admin user:
npm run beta-n
5. We can add scripts for different combinations.