量角器:在onprepare函数中调用方法

时间:2016-06-08 04:10:58

标签: javascript protractor

我试图在我的本地量角器配置中调用onPrepare方法中的自定义函数,该方法扩展了全局protrator配置但是无法使其工作。为了使它更简单,我在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中调用该方法

1 个答案:

答案 0 :(得分:1)

尝试此操作(将您的功能从导出对象移开):

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

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