我创建了一个函数,该函数从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
configure
而不是utility
,这就是它引发TypeError的原因。并且无论您想调用它的位置,都应按原样使用该变量名。这实际上是量角器,浏览器和其他内置全局变量were made available globally的方式。以下posting很有帮助,并且在protractor doc解释该属性时也很有用:params ?: any;
希望这会有所帮助,请告诉我。