I have a setting in my angular based website that turns a dropdown on and off. If it is off, then it does not show on the main page.
With Protractor, I need to check to see if this element is not present when the switch is off. However, I should not be thrown into Element Not Found Error, as it is one test in a set of many. How should I do this?
I have tried to do:
expect($$('.switch').count()).to.equal(0).and.notify(next);
But I am getting an AssertionError with this...
These answers do not wait for the element to disappear. In order to wait for it to disappear you need to use ExpectedConditions like below. InvisibilityOf detects whether an element has left the DOM. See it in the docs here: https://www.protractortest.org/#/api?view=ProtractorExpectedConditions.
I got it working by doing this:
stalenessOf
may be a good way to go: Protractor - ExpectedConditions.stalenessOfFor example you have a modal that is currently open. You close it and expect it to not be present:
Got the thing working by using something I found in the docs:
Also uses assertions, so it doesn't break cucumberjs.
none of these answers which include
count()
worked for me;you have to use the promise to pull the
count
value out like this.Another option that worked a bit better for me, and uses protractor 'way' of doing things http://angular.github.io/protractor/#/api?view=ElementArrayFinder.prototype.all
(I wanted to check that a loading indicator had disappeared)