量角器无法从JS文件中找到函数

问题描述 投票:0回答:1

我创建了一个函数,该函数从JS函数browser.forkNewDriverInstance()中返回新的Browser对象,并在配置文件中创建了一个全局变量,然后我使用该全局变量从该文件中调用了一个函数。但是在这里,当我调用该函数时,它会抛出类似utility.openNewBrowser is not a function错误的错误。

配置文件:

onPrepare: function () {

     global.utility=require("../src/test/resources/com.learnFramework.utility/timeOutConfig.js");
  }

黄瓜选项功能

cucumberOpts: {

//i'm using the same file for setting up the timeout.. is this creating the issue??

    require:['../src/test/resources/com.learnFramework.utility/timeOutConfig.js'],
    tags: false,
    profile: false,
    format:'json:../Reports/jsonResult/results.json',
    'no-source': true
}

功能

var configure = function () {
      this.setDefaultTimeout(100 * 1000);

        this.openNewBrowser=function(){
            return browser.forkNewDriverInstance(true);
        }
    };

    module.exports = configure;

错误日志

TypeError: utility.openNewBrowser is not a function
javascript protractor cucumberjs
1个回答
0
投票
您在上面所做的是定义全局变量的正确方法。但是我认为全局变量名称应为configure而不是utility,这就是它引发TypeError的原因。

并且无论您想调用它的位置,都应按原样使用该变量名。这实际上是量角器,浏览器和其他内置全局变量were made available globally的方式。以下posting很有帮助,并且在protractor doc解释该属性时也很有用:params ?: any;

希望这会有所帮助,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.