1
votes

I'd like to run different functions in my onPrepare function based on what capabilities I am running. I'd also like to be able to set capabilities from the command line. For example I run every test suite by typing "protractor" at the moment. Something like "protract -android" or "protractor directConnect = true" or anything that functions in a similar manner is what I am looking for.

Then in the onPrepare I have a function that maximizes my window which will not work when I run my android tests. I'm looking for a solution so that when I run the tests on android it just ignores that block of code.

1

1 Answers

1
votes

In protractor you can use global variables using params object in the config.js file. Try the below solution to solve your problem.

In config.js file create a params object with new variable as android.Following will be a demo config file.

exports.config = {

  seleniumAddress: 'http://localhost:4444/wd/hub',
  capabilities: {
    'browserName': 'chrome'
  },

  onPrepare: function () {
    if(browser.params.android == 'true'){
        //do whatever code you need to execute
     }else{

     }
  },
   params: {
    android: 'false',
  }
}

You can now pass the value for android variable as a commond line argument when you run the protractor test.

protractor config.js --params.android true