簡體   English   中英

量角器:在onprepare函數中調用方法

[英]Protractor: Call a method within onprepare function

我試圖在本地量角器配置的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中調用它

嘗試以下操作(將功能從導出對象移開):

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM