In my angular e2e test I would like to be able to tell if an element exists on the DOM, it's not an test expectation, just a condition I need.
I tried to do
element(".logout-button:visible").count() > 0
but count()
returns a future and won't work outside an expect()
. It seems that there is no way to add a callback when it resolves.
I tried to do
element(".logout-button:visible").query(element, callback)
But this one throws an exception when the element does not exist without bothering to go into my callback function. So how should I achieve this rather simple task?
Thanks!
Seeing as Angular scenario contains Jquery, you should be able to check for a specific condition using jQuery.
if($('#some-element:visible').length){
//do something
}
Alternatively, you could sleep() the test until you know the condition is met. For example:
element('#some-button').click();
sleep(10);
expect(element('#new-element:visibile').count()).toBe(1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.