I'm using protractor with angularjs to create my e2e tests. I have many files for which my specs array is quite big and I want to share a common function across all files. Is there a way to create a global beforeEach of some sort where I can inject my function? Does the exports.config object expose something so that I can have a common variable across all files? Currently I'm piggy backing off the "browser" variable but that can potentially be dangerous. Any help is much appreciated. Thanks
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes, you can easily do that using the onPrepare()hook in the protractor configuration:
exports.config = {
// ...
// A callback function called once protractor is ready and available, and
// before the specs are executed
// You can specify a file containing code to run by setting onPrepare to
// the filename string.
onPrepare: function() {
// you can also add properties to globals here
}
};
回答2:
This works wonderfully...Just make sure you properly terminate the previous config params by using proper delimiter ',' .
exports.config = {
seleniumAddress: **,**
onPrepare: function() {
browser.driver.manage().window().maximize();
}**,**
baseUrl:
}