【问题标题】:Protractor: Call a method within onprepare function量角器:在 onprepare 函数中调用方法
【发布时间】:2016-06-10 16:00:40
【问题描述】:

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

【问题讨论】:

    标签: javascript protractor


    【解决方案1】:

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

    var foo = function () {
        console.log('BAR')
    }
    
    exports.config = {
        //other params here
        onPrepare: function() {
            foo()
        },
        //other params here
    };
    

    【讨论】:

    • 虽然可行,但我需要将它放在 export.config 中,以便我可以在 local.protractor.config 中以某种方式覆盖它。将更新问题,因为我现在似乎需要更新
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 2017-05-26
    相关资源
    最近更新 更多