如何在Angularjs量角器中使用命令行参数?

时间:2021-04-06 23:16:03

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.

我使用量器来执行一些端到端测试,我希望通过命令行传入登录凭据,而不是将它们存储在spec文件中。我找到一个帖子,有人用了process.argv。forEach,但是如何存储这些值并在另一个spec文件中使用它们呢?我有一个文件叫做login-spec。这里我想使用命令行参数。

Thanks!

谢谢!

1 个解决方案

#1


84  

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

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

您可以在代码中访问params对象: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.user and browser.params.login.password

browser.params.login。用户和browser.params.login.password

#1


84  

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

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

您可以在代码中访问params对象: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.user and browser.params.login.password

browser.params.login。用户和browser.params.login.password