0

I am creating a page object that needs to have a function to check whether a group of elements is disabled.

I have tried the following but it does not work.

areAllElementsDisabled: function (allElements) {
        return allElements.filter(function (elem) {
            return elem.isEnabled().then(function (isEnabled) {
                return isEnabled;
            });
        }).length===0;
    }

Can anybody suggest a way to solve the issue? Thank you!

Kabachok
  • 573
  • 1
  • 7
  • 22

2 Answers2

0

If anybody is stuck with a similar problem, I have found a way that works for me:

areAllElementsDisabled: function (allElements) {
            var allElemetsPromises = allElements.map(function(elem){
                return elem.isEnabled();
            });

            return Promise.all(allElemetsPromises).then(function(values){
                return values.every(function(value){
                    return !value;
                })
            });
        }
Kabachok
  • 573
  • 1
  • 7
  • 22
0

You can call count() on filtered elements to make code more simple:

areAllElementsDisabled: function (allElements) {
    return allElements.filter(function (elem) {
        return elem.isEnabled();
    }).count(function(cnt){
        return cnt === 0;
    });
}
yong
  • 13,357
  • 1
  • 16
  • 27