首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将参数传递给npm脚本以执行

将参数传递给npm脚本以执行
EN

Stack Overflow用户
提问于 2020-08-03 18:03:09
回答 2查看 4.2K关注 0票数 2

我正在尝试使用量角器执行测试,我想使用行命令通知用户和密码登录到应用程序,但它对我不起作用:

这是我的package.json:

代码语言:javascript
运行
复制
 "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "local": "ng serve --configuration hmr --host local.dev.net",
    "build": "ng build --prod",
    "build:devtest": "npm run i18n && ng build -c devtest",
    "build:dev": "npm run i18n && ng build -c dev",
    "build:qatest": "npm run i18n && ng build -c qatest",
    "build:preprd": "npm run i18n && ng build -c preprd",
    "build:prd": "npm run i18n && ng build -c prd",
    "pree2emom": "tsc",
    "e2e": "protractor dist/out-tsc/e2e/cucumberconfig.js $USER $PASS",

.
.
.
}

我在控制台上写道:

代码语言:javascript
运行
复制
npm run e2e $USER='--params.login.user=User01'  $PASS='--params.login.password=Pass01'

这就是错误:

代码语言:javascript
运行
复制
> fdr-ui@2.2.1 e2e C:\Users\cpaez\Documents\Automation\Automation\fdr-ui
> protractor dist/out-tsc/e2e/cucumberconfig.js $USER $PASS "=--params.login.user=User01" "=--params.login.password=Pass01"   

Usage: protractor [configFile] [options]
configFile defaults to protractor.conf.js
The [options] object will override values from the config file.
See the reference config for a full list of options.

Opciones:
  --help                                 Print Protractor help menu   [booleano]
  --version                              Print Protractor version     [booleano]
  --browser, --capabilities.browserName  Browsername, e.g. chrome or firefox
  --seleniumAddress                      A running selenium address to use
  --seleniumSessionId                    Attaching an existing session id
  --seleniumServerJar                    Location of the standalone selenium jar
                                         file
  --seleniumPort                         Optional port for the selenium
                                         standalone server
  --baseUrl                              URL to prepend to all relative paths
  --rootElement                          Element housing ng-app, if not html or
                                         body
  --specs                                Comma-separated list of files to test
  --exclude                              Comma-separated list of files to
                                         exclude
  --verbose                              Print full spec names
  --stackTrace                           Print stack trace on error
  --params                               Param object to be passed to the tests
  --framework                            Test framework to use: jasmine, mocha,
                                         or custom
  --resultJsonOutputFile                 Path to save JSON test result
  --troubleshoot                         Turn on troubleshooting output
  --debuggerServerPort                   Start a debugger server at specified
                                         port instead of repl
  --disableChecks                        Disable cli checks
  --logLevel                             Define Protractor log level [ERROR,
                                         WARN, INFO, DEBUG]
  --explorer, --elementExplorer          Interactively test Protractor commands

Error: more than one config file specified
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fdr-ui@2.2.1 e2e: `protractor dist/out-tsc/e2e/cucumberconfig.js $USER $PASS "=--params.login.user=User01" "=--params.login.password=Pass01"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fdr-mom-ui@2.2.1 e2e script.

因为我想在如下所示的函数中使用参数:

代码语言:javascript
运行
复制
BeforeAll(async function ()
    await browser.get('https://web/#login/');
    await browser.sleep(10000)
    await log.email.sendKeys(browser.params.login.user);
    await log.pass.sendKeys(browser.params.login.password);
    await log.go.click();
    await browser.sleep(20000);
});

提前谢谢你

EN

Stack Overflow用户

回答已采纳

发布于 2020-08-06 11:14:54

这比你想象的要容易。只要去掉命令中的$USER=和$PASS=部分即可。

命令应如下所示:

代码语言:javascript
运行
复制
npm run e2e --params.login.user=User1 --params.login.password=Pass01

您还需要在package.json中修改脚本。将其更改为以下内容,即可完成所有设置。

代码语言:javascript
运行
复制
"e2e": "protractor dist/out-tsc/e2e/cucumberconfig.js"
票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63227392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档