Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters from npm command to protractor config file

Tags:

npm

protractor

How to pass parameters from npm command to protractor config file

I have protractor config file:

exports.config = {

allScriptsTimeout : 30000,

suites : {        
   login2 : 'e2e/TestSuites/Full/LoginTestSuite/ValidInvalidLogins.js',
},
// configure multiple browsers to run tests
multiCapabilities : [
{
   'browserName' : 'chrome'
    //'browserName': 'firefox'
} ],
baseUrl :'http://localhost:8080',
framework : 'jasmine2',
jasmineNodeOpts : {
    defaultTimeoutInterval : 30000
 },
};

and npm package.json file :

 "scripts": {   
"e2e-bvt": "protractor tests/protractor-conf-BVT.js --baseUrl $baseUrl",    
 },

I want to pass --baseUrl = http://testurl:8080 to npm command so that protractor config file can take this parameter to run test against different baseUrl.

how can I achieve something like:

 npm run e2e-bvt --$baseUrl=http://testurl:8080
like image 841
ssharma Avatar asked Aug 02 '16 20:08

ssharma


1 Answers

You need to add "--" next to your npm run command and then pass all required parameters.

  "scripts": {   
      "e2e-bvt": "protractor tests/protractor-conf-BVT.js",    
  } 

npm run e2e-bvt -- --baseUrl=http://testurl:8080

the above command will take all the argumnets (--baseUrl=http://testurl:8080) and pass this argument to the script e2e-bvt.

like image 188
Sudharsan Selvaraj Avatar answered Nov 15 '22 09:11

Sudharsan Selvaraj