Praveen
Praveen

Reputation: 1418

Not able to return an array containing column values from an ag-grid table back to the function

I have written a function which reads a given column in ag-grid and storing it in an array.

getSortedText(columnName: string){
var testArrayAsc = [];
element.all(by.css('div.ag-body-container > [role="row"]')).then(function(count) {
  console.log("Row Count= ", Object.keys(count).length);
  for (let rowNo = 0; rowNo < Object.keys(count).length; rowNo++) {
    element.all(by.css(String.Format("div.ag-body-container div[ row-index='{0}'] > [col-id='{1}']", rowNo, columnName))).map(function (Element) {
     Element.getText().then(function (result) {
       console.log("Result Asc :: " + result);
       testArrayAsc.push(result);
     });
    })
  }
}).then(function () {
    console.log("TestArrayAsc::",testArrayAsc);
    return testArrayAsc;
})
}


I am calling this function from my test by:

console.log('Array::', homepage.getSortedText('Betreff'));


But I am getting "Array:: undefined" as output.
And If i modify my code like this:

homepage.getSortedText('Betreff').then(function (a) {
})


Then I am getting this error message in IDE: "Property 'then' doesnot exist on type 'void'".
Please help. Thanks in advance.

Upvotes: 0

Views: 231

Answers (1)

Chris Cook
Chris Cook

Reputation: 514

getSortedText doesn't return anything, hence it being void type and not having a then method.

There's a lot of missing information but a starting point is to return the Promise you're creating.

return element.all(

Upvotes: 1

Related Questions