I'm working with nightwatch js and have issues calling .then method on promise from a different js file.
I've a getCount.js file.
module.exports.command = function () {
return new Promise((resolve,reject) => {
var localSelector = 'div.flex.mt-4.v-card.v-sheet.theme--light > div > div > table > tbody';
var rowSelector = localSelector + ' > tr';
this.elements('css selector', rowSelector, function (result) {
if (result.status) {
console.log("Inside IF do promise " + result.value.length)
reject(result.status);
} else {
console.log("Inside ELSE do promise " + result.value.length)
resolve(result.value.length);
}
});
});
};
and here is my home.js where I'm trying to call my promise. However getting below error
module.exports = {
url: 'http://localhost:8080/',
elements: {
servicePageTitle :{
selector : 'div.v-card__title > div > span:nth-child(2)'
},
tableBody :{
selector : 'div.flex.mt-4.v-card.v-sheet.theme--light > div > div > table > tbody'
}
},
commands: [{
clickService(selector,serviceName){
return this
.searchTable(selector,serviceName)
},
testPromise(){
this.getCount().then(function(v){
console.log("Total is " + v)
});
}
}]
};
Calling::
const page = browser.page.home();
page.navigate().testPromise();
Now my total is undefined.. Here is output:
Running: Dashboards:firstTest
Inside ELSE do promise 10
Total is undefined
No assertions ran.
Thanks in advance!