6

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
ssharma
  • 935
  • 2
  • 19
  • 43
  • when I am executing this its throwing error: `invalid element state: Failed to execute 'replace' on 'Location': '$baseUrl#/Account/LogIn' is not a valid URL.` – ssharma Aug 02 '16 at 21:13

2 Answers2

10

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.

Sudharsan Selvaraj
  • 4,792
  • 3
  • 14
  • 22
  • Thanks @Sudharsan this helped. – ssharma Aug 03 '16 at 14:20
  • Also you can pass other params as well (i am using to debug locally with different users). Just check this line in config - https://github.com/angular/protractor/blob/master/docs/referenceConf.js#L280 – Xotabu4 Aug 03 '16 at 21:48
0

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

baseUrl="http://testurl:8080" npm run e2e-bvt
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 1
    Tried running above command and it gives `'baseUrl' is not recognized as an internal or external command,operable program or batch file.` I am running this from windows machine. – ssharma Aug 03 '16 at 14:17