且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Angularjs Protractor 中使用命令行参数?

更新时间:2023-02-22 11:32:56

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

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