I write this script under the module:
var enter_search = function () { this.clickSearch = function (value) { element(by.id('searchbutton')).click(); }; this.waitElementFound = function (value) { var EC = protractor.ExpectedConditions; browser.wait(EC.presenceof(value), 35000); }; }; module.exports = new enter_search();
and to call this function on my spec, i wrote this:
var search = require('enter_search'); var loadtxt = element (by.id('text')); it('waits for the element', function(){ search.waitElementFound(loadtxt); search.clickSearch(); });
When I execute the test, it gives me an error undefined function. Not sure what went wrong. Thanks
To use functions from one file in another, you should export the function and then require it in the other file. Here's an example -
File test.js
var search = require('./helper.js');
var loadtxt = element(by.id('text'));
it('waits for the element', function(){
search.waitElementFound(loadtxt);
});
File helper.js
var waitElementFound = function (value) {
var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(value), 35000);
};
module.exports = new waitElementFound(); //export the function
Hope this helps.
我已经解决了这个问题,我只需要在var x = function之外声明我的变量..新手的挣扎:)无论如何,谢谢@Girish Sotur
var enter_search = function () { this.clickSearch = function (value) { element(by.id('searchbutton')).click(); }; this.waitElementFound = function (value) { var EC = protractor.ExpectedConditions; browser.wait(EC.presenceof(value), 35000); }; }; module.exports = new enter_search();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.