Wednesday, March 20, 2019

How to use Azure pipeline variables in Protractor automatic tests

Nowadays Microsoft Azure DevOps is very popular for Software development with the Agile way of working.

Protractor (with Selenium) is widely used for UI automation testing. It is useful to add flexibility to the Protractor test setup. You can find a blog: here.

However, the module.exports in that blog does not work for me, maybe because of the fact that I use exports.config, as follows:

exports.config = {
  framework: 'jasmine2',
  SELENIUM_PROMISE_MANAGER: false,
  suites: {
    newStyle: [
      'spec1.js',
    ],
  },

The parameter block can be added inside the exports.config,

  params: {
    login: {
      user: 'default',
      password: 'default'
    }
  }

In the spec file, the params can be used as follows, e.g.

let usr =browser.params.login.user; 
let pw = browser.params.login.password; 

Locally, you may run the Protractor tests by using the command line,

Protractor conf_*.js --params.login.user=someUserName --params.login.password=somePassword

The values of default are replaced by "someUserName" and "somePassword" in the runtime.

It works fine! If you use npm module combined with the Azure DevOps, then the relevant part of the package.json looks like as follows:

 "test": "protractor conf*.js --suite newStyle --params.login.user=__UserNameUITest__ --params.login.password=__PasswordUITest__",



Where the __UserNameUITest__, and __PasswordUITest__ are the tokens variables, which have to be replaced by the pipeline variables.

Then in the pipeline, you can just use:

 npm run test 

Last but not least, before this works you need to define two pipeline variables:

UserNameUITest          someUserName (shown as ****** ) and

PasswordUITest           somePassword (shown as ******), using the lock. 

 --- End of blog ----