Reputation: 2217
In protractor I would like to assert that all elements are displayed that have a particular css class. But syntax like this doesn't work.
expect(element.all(by.className('bill')).each(x => x.isDisplayed().toBeTruthy());
What's the protractor way of achieving this goal? Is this it?
let els = element.all(by.className('bill'));
els.then(x => {
x.forEach(y => {
expect(y.isDisplayed()).toBeTruthy();
})
});
This works, but seems overly complex.
Upvotes: 2
Views: 717
Reputation: 2217
In the end, I did this:
let billEls = element.all(by.className('bills'));
billEls.then(elements => {
elements.forEach(el => {
expect(el.isDisplayed()).toBeTruthy();
})
});
but would have preferred the @FlorentB's .reduce method.
Upvotes: 0
Reputation: 42528
You could first convert the items to an array of booleans with map
and then assert that the array doesn't contain false
:
var elems = element.all(by.className('bill'));
expect(elems.map(e => e.isDisplayed())).not.toContain(false);
You coulds also use reduce
to aggregate the state returned by isDisplayed
:
var elems = element.all(by.className('bill'));
expect(elems.reduce((acc, e) => acc && e.isDisplayed())).toBeTruthy();
Upvotes: 2