我可以访问量角器配置文件中的参数吗? [英] Can I access parameters in my protractor configuration file?
问题描述
我通过运行以下命令开始我的量角器测试:
I start my protractor tests by running the following:
protractor protractor.conf.js --params.baseUrl=http://www.google.com --suite all
我想运行一个启动前"函数,该函数依赖于一个参数(在本例中为 baseUrl).有可能吗?
I would like to run a 'before launch' function which is dependant of one parameter (in this case, the baseUrl). Is it that possible?
exports.config = {
seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',
seleniumPort: 4455,
suites: {
all: 'test/*/*.js',
},
capabilities: {
'browserName': 'firefox'
},
beforeLaunch: function() {
console.log('I want to access my baseUrl parameter here: ' + config.params.baseUrl);
},
onPrepare: function() {
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('output/xmloutput', true, true));
}
};
如果我运行它,我会收到一个 ReferenceError,因为未定义配置.我该怎么做?这可能吗?
If I run that I get a ReferenceError because config is not defined. How should I do that? Is that even possible?
推荐答案
我不确定是否在 beforeLaunch()
阶段设置了量角器全局变量,但它们肯定可以在 使用onPrepare()
步骤.
I am not completely sure if protractor globals are set at the beforeLaunch()
stage, but they are definitely available at onPrepare()
step.
通过全局browser
对象访问params
对象:
Access the params
object through the global browser
object:
console.log(browser.params.baseUrl);
更新:使用 Jasmine 2.6+,量角器 4.x,browser.params 为空,但以下在 onPrepare()
步骤中有效:
Update:
Using Jasmine 2.6+, protractor 4.x, browser.params was empty, but the following worked in onPrepare()
step:
console.log(browser.baseUrl);
这篇关于我可以访问量角器配置文件中的参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!