I have created a utility function for getting the total size of the webtable using protractor and javascript.
this.getTableSize = function(tableElement, rowSelector, columnSelector){
return {
row: tableElement.all(rowSelector).count(),
column : tableElement.all(columnSelector).count()
}
};
However on using the same function , i am geeting the error:
tableActions.getTableSize(table,by.css("tr"),by.css("th")).then(function(obj){
console.log(obj);
})
The error which i am getting is :
TypeError: tableActions.getTableSize(...).then is not a function
The reason your code is failing is because you are using .then()
on a function that does not return a promise
.
Here's an example of a working promise
:
let promise1 = new Promise( (resolve, reject) => {
let dataReceivedSuccessfully = false;
if (dataReceivedSuccessfully) {
resolve('Data Available!');
}
if (!dataReceivedSuccessfully) {
reject('Data Corrupted!');
}
})
promise1.then( (success) => {
console.log(success);
}).catch( (err) => {
console.log(err);
})
You can use this in your code to return a resolve
or reject
, and then you will be able to use .then()
.
https://medium.freecodecamp.org/promises-in-javascript-explained-277b98850de
You need to correct your method to handle the promises correctly.
I assume that tableElement.all(rowSelector).count() returns a promise else you will have to handle the callbacks;
this.getTableSize = function (tableElement, rowSelector, columnSelector) { return Promise.all([tableElement.all(rowSelector).count(), tableElement.all(columnSelector).count()]).then(function(data) { return { row: data[0], column: data[1] } }) }; tableActions.getTableSize(table, by.css("tr"), by.css("th")).then(function (obj) { console.log(obj); })
Promise.all does not return the array of resolved data with bluebird promises so use.
this.getTableSize = function (tableElement, rowSelector, columnSelector) { return ableElement.all(rowSelector).count().then(function(c) { return ableElement.all(columnSelector).count().then(function (c2) { return { row: c, column: c2 } }) }) }; tableActions.getTableSize(table, by.css("tr"), by.css("th")).then(function (obj) { console.log(obj); })
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.