Below is the code where I am unable to return value from GenericUtil.js to homepage.js
I am trying to implement Page objects along with Hybrid driven framework.
//GenericUtil.js:
var blnFlag;
GenericUtilities = function(){
this.objClick = function(objLocator){
element.all(objLocator).then(function(items) {
if (items.length == 1) {
element(objLocator).click();
blnFlag='True';
console.log("Inside if" + blnFlag);
}
else {
blnFlag='False';
console.log("inside else" + blnFlag);
};
});
return blnFlag;
};
};
module.exports = new GenericUtilities();
//home_page.js:
var blnFlag;
var gu = require("../GenericUtilities/GenericUtil.js");
var home_page = function(){
this.clickContinue = function(){
blnFlag = gu.objClick(home_page_obj.btnContinue);
console.log("After return" + blnFlag );
};
};
module.exports = new home_page();
//The value is being returned as undefined.
Try something like this :
//GenericUtil.js:
var blnFlag,
GenericUtilities = function(){
this.objClick = function(objLocator){
element.all(objLocator).then(function(items) {
if (items.length == 1) {
element(objLocator).click();
blnFlag='True';
console.log("Inside if" + blnFlag);
}
else {
blnFlag='False';
console.log("inside else" + blnFlag);
};
});
return blnFlag;
};
};
module.exports = GenericUtilities;
//home_page.js:
var blnFlag,
GenericUtilities = require("../GenericUtilities/GenericUtil.js"),
gu = new GenericUtilities(),
home_page = function(){
this.clickContinue = function(){
blnFlag = gu.objClick(home_page_obj.btnContinue);
console.log("After return" + blnFlag );
};
};
module.exports = new home_page();
//The value is being returned as undefined.
EDIT: this is what i have done then
//GenericUtil.js:
var GenericUtilities = function () {
this.bnlFlag = 'False';
this.action = function () {
this.bnlFlag = 'True';
};
};
module.exports = new GenericUtilities();
//home_page.js:
var bnlFlag,
gu = require("./generic.js"),
home_page = function(){
this.clickContinue = function(){
bnlFlag = gu.bnlFlag;
console.log("Before return " + bnlFlag );
gu.action();
bnlFlag = gu.bnlFlag;
console.log("After return " + bnlFlag );
};
};
module.exports = new home_page();
// test in an other file
var home = require('./home.js');
home.clickContinue();
And this is working :
Before return False
After return True
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.