【问题标题】:How to pass parameters from npm command to protractor config file如何将参数从 npm 命令传递到量角器配置文件
【发布时间】:2016-08-03 13:08:20
【问题描述】:

如何将参数从 npm 命令传递到量角器配置文件

我有量角器配置文件:

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
 },
};

和 npm package.json 文件:

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

我想将 --baseUrl = http://testurl:8080 传递给 npm 命令,以便量角器配置文件可以使用此参数对不同的 baseUrl 运行测试。

我怎样才能达到这样的效果:

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

【问题讨论】:

  • 当我执行它时抛出错误:invalid element state: Failed to execute 'replace' on 'Location': '$baseUrl#/Account/LogIn' is not a valid URL.

标签: npm protractor


【解决方案1】:

您需要在 npm run 命令旁边添加“--”,然后传递所有必需的参数。

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

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

上述命令将获取所有 argumnets (--baseUrl=http://testurl:8080) 并将此参数传递给脚本 e2e-bvt。

【讨论】:

【解决方案2】:

您没有正确地将参数传递给脚本。让我们申请this approach

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

【讨论】:

  • 尝试运行上面的命令,它给出了'baseUrl' is not recognized as an internal or external command,operable program or batch file.我正在从 Windows 机器上运行它。
猜你喜欢
  • 1970-01-01
  • 2021-02-14
  • 1970-01-01
  • 2011-09-28
  • 1970-01-01
  • 1970-01-01
  • 2017-01-12
  • 1970-01-01
  • 2012-07-26
相关资源
最近更新 更多