gpt4 book ai didi

javascript - Protractor:在 onprepare 函数中调用方法

转载 作者:行者123 更新时间:2023-12-03 06:47:04 25 4
gpt4 key购买 nike

我试图在本地 Protractor 配置的 onPrepare 方法中调用自定义函数,该函数扩展了全局 Protractor 配置,但无法使其工作。为了使它更简单一点,我在 protractor.config 中这样写

module.exports = {
foo: function() {
console.log('testing');

},
// 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() {
// At this point, global 'protractor' object will be set up, and jasmine
// will be available. For example, you can add a Jasmine reporter with:
// jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter(
// 'outputdir/', true, true));




console.log(foo);


},
};

我的 local.protractor.config 是

var globalConf = require('./protractor.conf.js');
exports.config = globalConf;

但是我收到错误,因为 foo 未定义。

[launcher] Error: ReferenceError: foo is not defined

有没有办法添加 onprepare 可以调用的自定义方法,我可以在 local.protractor.config 中调用它

最佳答案

试试这个(将你的函数从导出对象中移开):

var foo = function () {
console.log('BAR')
}

exports.config = {
//other params here
onPrepare: function() {
foo()
},
//other params here
};

关于javascript - Protractor:在 onprepare 函数中调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37693078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com