I have been working on creating a function that can search through an array of elements and return the first element that meets certain criteria.
Here is my test code that works as expected:
element.all(by.css('_cssSelector_')).filter(function(elms, index) {
return elms.getAttribute('height').then(function(height) {
return parseInt(height) > 0;
});
}).then(function(validElms) {
browser.actions().mouseMove(validElms[0]).perform();
}
However, when I refactor this into a separate function, it does NOT work:
getValidElm = function() {
var validElm = element.all(by.css('_cssSelector_')).filter(function (elms, index) {
return elms.getAttribute('height').then(function (height) {
return parseInt(height) > 0;
});
}).then(function (validElms) {
return validElms[0];
});
return validElm;
}
When I run the following code:
var validElmFromPage = getValidElm();
console.log(validElmFromPage);
I receive: Promise::2046 {[[PromiseStatus]]: "pending"}
This seems to indicate that there is an issue with resolving something inside the function before using the variable outside the function. Despite researching extensively and reading various resources, I am still unable to pinpoint the problem. It appears to be related to controlFlow in some way?
Thank you for any assistance you can provide.