javascript - Unable to pass values from one js file to another js file protractor e2e testing -


below code unable return value genericutil.js homepage.js

i trying implement page objects along 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 being returned undefined. 

try :

//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 being returned undefined. 

edit: 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 other file var home = require('./home.js'); home.clickcontinue(); 

and working :

before return false after return true 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -