4

I'm running into an issue with Protractor while writing my angularjs e2e tests.

The error it's throwing is Failed: Wait timed out after 1025ms for the following code. This test is specifically for the Ionic Modal, so it has a transition that lasts less than 1000ms.

it('should close the modal on button click', function () {
    expect(modal.isPresent()).toBeTruthy();
    element(by.css(merchantInfoClose)).click();        
    // wait for close animation to complete
    browser.driver.wait(function() {
        return !browser.isElementPresent(modal);
    }, 1000).then(function() {
        expect(modal.isPresent).toBeFalsy();
    });
});

I'm pretty stuck on how to resolve this issue, and have read through many of the SO posts about the timeout issues with protractor, and none of them have helped. Any ideas on what I'm doing wrong here?

Aaron
  • 2,367
  • 3
  • 25
  • 33
robert
  • 819
  • 1
  • 10
  • 24
  • I experienced a very similar issue with ui bootstrap modals, and it turns out it may have been due at least in part to css transitions interfering with Protractor's ability to identify whether an element (the close button) was present and clickable. Resolved by disabling css transitions: http://stackoverflow.com/a/32264842/446030 – JcT Aug 28 '15 at 07:33

2 Answers2

3

Since there is no way for us to reproduce the problem, we can only assume and propose possible solutions. I would try to use stalenessOf expected condition:

An expectation for checking that an element is not attached to the DOM of a page.

var EC = protractor.ExpectedConditions;
browser.wait(EC.stalenessOf(modal), 1000);
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
3

Could it be that the modal is always present, but that its visibility is toggled? Then, I suspect you should check for the element being visible instead of present:

expect(modal.isDisplayed()).toBeTruthy();

See also How to use protractor to check if an element is visible?.

You can then probably also use expected conditions as suggested by @alecxe, using ExpectedConditions.visibilityOf.

I also find it somewhat suspicious that the click() promise is not followed by a then. Does the following work?

element(by.css(merchantInfoClose)).click().then(function() {
  expect(modal.isDisplayed()).toBeFalsy();
}

This would assume the modal informs Angular when it is ready animating, and that Protractor is able to figure out itself that it should wait for that.

Community
  • 1
  • 1
avandeursen
  • 8,458
  • 3
  • 41
  • 51