如何在 Angularjs Protractor 中使用命令行参数? [英] How can I use command line arguments in Angularjs Protractor?

查看:30
本文介绍了如何在 Angularjs Protractor 中使用命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Protractor 执行一些端到端测试,我想通过命令行传递登录凭据,而不是将它们存储在规范文件中.我发现有人使用 process.argv.forEach 的帖子,但是我如何存储这些值并在另一个规范文件中使用它们?我有一个名为 login-spec.js 的文件,我想在其中使用命令行参数.

I'm using Protractor to perform some end to end tests, and I'd like to pass in login credentials through the command line instead of storing them in a spec file. I found one post where someone used process.argv.forEach, but how can I store those values and use them in another spec file? I have a file called login-spec.js where I'd like to use the command-line arguments.

谢谢!

推荐答案

参考配置 这部分可能很有趣:

In the reference config this section can be interesting:

  // The params object will be passed directly to the protractor instance,
  // and can be accessed from your test. It is an arbitrary object and can
  // contain anything you may need in your test.
  // This can be changed via the command line as:
  //   --params.login.user 'Joe'
  params: {
    login: {
      user: 'Jane',
      password: '1234'
    }
  },

您可以在代码中像这样访问 params 对象:browser.params.login.user

And you can access the params object like this in your code: browser.params.login.user

因此,如果您像这样调用量角器:

So in your case if you call protractor like this:

protractor ... --params.login.user=abc --params.login.password=123

您可以像这样在代码中访问这些变量:

You can access these variables in your code like this:

browser.params.login.userbrowser.params.login.password

这篇关于如何在 Angularjs Protractor 中使用命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆