如何使用量角器 conf 传递命令行参数 [英] how to pass command line arguments with protractor conf
问题描述
我们有量角器-黄瓜框架作为 e2e 测试.到目前为止,我们使用 conf 文件,并在 conf json 中静态提及环境详细信息.我想通过 protractor_conf 文件传递用户定义的参数,如下所示.
We have protractor-cucumber framework as e2e test. Till now we use the conf file with statically mentioning the environment details inside the conf json. I would like to pass user defined arguments with the protractor_conf file something like below.
protractor protractor_conf.js -DbrowserName=chrome -DexecPlatform=(native/sauce)
并希望在 conf.js 中获取此参数并在功能部分下进行替换.我无法在网上获得正确的详细信息,因此将不胜感激任何帮助/建议.
and would like to fetch this argument inside the conf.js and substitute under the capabilities section. I could not get proper details on net, so any help/suggestions would be appreciated.
推荐答案
您可以在 conf.js 文件中添加参数,然后从命令行传递 arugs.
You can add Parameters in your conf.js file then pass the arugs from the command line.
这是一个例子.
// The params object will be passed directly to the Protractor instance,
// and can be accessed from your test as browser.params. 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.environment.Browser "Firefox"
params: {
environment: {
browser: 'Chrome',
execPlatform: 'sauce',
password: 'default'
}
}
现在我们可以从命令行传递 arugs
Now from we can pass the arugs from command line
protractor conf.js --parameters.environment.browser= Firefox --parameters.environment.execPlatform=sauce --parameters.environment.password=password123
接下来,您还可以在规范文件中引用这些参数.
Next, you can also refer these parameters in your spec file.
describe('describe some test', function() {
it('describe some step', function() {
$('.password').sendKeys(browser.params.login.password);
});
});
设置参数有很多好处.
- 如果我们知道将在多个规范文件(即登录电子邮件和密码)中使用相同的值,则参数非常适合消除不必要的重复.
- 能够在运行时更改参数值可以更轻松地使用不同的数据运行相同的测试.
- 提高安全性 – 在规范文件中硬编码密码并不是一个好方法.参数使您能够将它们排除在外,而是在运行时提供它们.
这篇关于如何使用量角器 conf 传递命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!