Tom Nijs Tom Nijs - 1 year ago 81
AngularJS Question

Protractor timeouts

I've been developing automated tests in Protractor for quite some time and like many of you, I've run into gaps which can only be crossed with the

-bridge. I'm not a fan of hard coding things such as this but if it's a necessity I will.

The tests I've developed have brought me to a point where every
has a major impact on my runtime. The tests are currently testing permissions for different accounts (128 exactly) and this involves logging in and out whilst checking what every account has and has not received access to.

The website I'm testing is a pure AngularJS application which, in my eyes, should make
a deprecated method since there is a
method that accurately waits until the page is fully loaded compared to
which waits a set amount of time and if your website isn't loaded within that time (it happens), you'll have an inconsistent test (nobody likes inconsistency).

Research has led me to believe that
does not take into account animations and related time-consuming features since they're not AngularJS related yet this is not implemented in our website. Also
basically waits for
, and

What I'm asking is wether this is something which is regarded as an acceptable loss since Protractor is great in general or is there something I'm overlooking here?

Are there solutions out there to allow us not to settle for

Sources: Protractor Timeout Docs,
Timeout-spec.js (protractor docs),
Issue909, Issue279, Issue92, StackQuestion1

Answer Source

If you can devise some sort of test to determine if whatever you're waiting for has completed, you can use browser.wait. Taking ideas from from, you can pass a function that returns a promise that resolves to true or false, such as one that uses isPresent

browser.wait(function() {
  return element('some-element')).isPresent();
}, 1000);

or if you have some more complicated condition you can use promise chaining:

browser.wait(function() {
  return element('some-element')).isPresent().then(function(isPresent) {
    return !isPresent;
}, 1000);

and the command flow will wait, repeatedly calling the function passed to wait, until the promise it returns resolves to true.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download