如何使用命令行参数在Angularjs量角器? [英] How can I use command line arguments in Angularjs Protractor?
问题描述
我用量角器来执行一些端到端的测试,我想通过命令行的登录凭据传递它们存储在一个规范文件,而不是。我发现一个帖子里有人用 process.argv.forEach
,但我怎么可以存储这些值,而在另一个spec文件使用它们?我有一个名为登录-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.
谢谢!
推荐答案
在 referenceConf.js 这部分可能是有趣的:
In the referenceConf.js 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对象像这样在你的code: 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
您可以访问您code这些变量是这样的:
You can access these variables in your code like this:
browser.params.login.user
和 browser.params.login.password
这篇关于如何使用命令行参数在Angularjs量角器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!