Santi
Santi

Reputation: 31

Protractor test failing with angular-growl-v2

I'm using angular-growl-v2 notifications in my app.

They work ok, the problem comes on my protractor tests. I have to use a TTL (around 6 seconds) as it is a requirement. Then I have the following test:

it('should send a request and notify the user about the result',function(){
    detailPage.verifyEmailtButton.click().then(function(){
      var expectedDiv = element(by.css('.alert-success'));
      expect(expectedDiv).toBeDefined();
    });
  });

But it is always throwing an error:

NoSuchElementError: No element found using locator: By.cssSelector(".alert-success")

This does not happens when the TLL is -1.

Someone can help here? Thanks in advance.

Upvotes: 3

Views: 443

Answers (2)

adamvert
adamvert

Reputation: 625

angular-growl-2 uses $timeout, which doesn't play nicely with protractor: protractor waits for the timeout to end before it completes its sync with angular process.

So by the time it reaches your expect call, the timeout has elapsed and the alert is no longer there. Check out the Waiting for page synchronization section of this doc:

https://github.com/angular/protractor/blob/master/docs/timeouts.md

(This page relates to timeouts, which you don't appear to be experiencing, but since the default timeout is 11 seconds, it could well be that the entire process, including your 6 second TTL, takes place before a timeout happens)

There's a PR to angular-growl-v2 to use $interval instead of $timeout, but its currently waiting for tests:

https://github.com/JanStevens/angular-growl-2/pull/85

Upvotes: 1

alecxe
alecxe

Reputation: 473823

Explicitly wait for the alert to be present after clicking the button:

detailPage.verifyEmailtButton.click();

var EC = protractor.ExpectedConditions;

var expectedDiv = element(by.css('.alert-success'));
browser.wait(EC.presenceOf(expectedDiv), 10000, "No alert present");

Upvotes: 0

Related Questions