ssharma
ssharma

Reputation: 941

How to pass parameters from npm command to protractor config file

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

Upvotes: 6

Views: 5406

Answers (2)

Sudharsan Selvaraj
Sudharsan Selvaraj

Reputation: 4832

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.

Upvotes: 10

alecxe
alecxe

Reputation: 473873

You are not passing arguments to the script correctly. Let's apply this approach:

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

Upvotes: 0

Related Questions