Reputation:
I am using the Protractor software for my end to end tests. Some elements are being set with ng-show.
Can someone tell me how I can check if these elements are visible or not with Protractor ?
Upvotes: 10
Views: 16605
Reputation: 13740
Assuming you have many elements by the same id/class and you want to assert
on the count of number of visible elements
var elements = element.all(by.id('foo'))
.filter(function(el){
return el.isDisplayed();
});
expect(elements.count()).toEqual(2);
Upvotes: 1
Reputation: 46
expect knows to deal with promise so the following works.
expect($('#foo').isDisplayed()).toBe(true);
Upvotes: 1
Reputation: 1136
I've found that isDisplayed() returns a promise, and in the .then, you are passed the boolean. So looks more like this:
$('#foo').isDisplayed().then(function(isDisplaying) {
expect(isDisplaying).toBe(true);
});
Upvotes: 2
Reputation: 692231
Assuming that your element has the ID "foo", you could do, for example
expect($('#foo').isDisplayed()).toBe(true); // or false to test that it's hidden
or
expect(element(by.id('foo')).isDisplayed()).toBe(true);
Upvotes: 14