Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

WaitForAngular does not wait for $routeChangeSuccess event #1641

Closed
0xR opened this issue Dec 16, 2014 · 5 comments
Closed

WaitForAngular does not wait for $routeChangeSuccess event #1641

0xR opened this issue Dec 16, 2014 · 5 comments

Comments

@0xR
Copy link

0xR commented Dec 16, 2014

Scenario:
Click on an element
A route is loaded using $location
The $routeChangeSuccess event is fired
Its eventhandler loads the contents of the page using an $http call

Protractor code:
element(...).click()
element(...).first().getText()

Error:
Index out of bound. Trying to access element at index:0, but there are only 0 elements

Expected outcome:
No error, but a future containing the text of the elemement

If my expectation is correct and this is not a known bug I can provide a code example.

I debugged this using notifyWhenNoOutstandingRequests to log on the console when angular was ready. And other console.log calls when the $http call was made and finished.

My output looks like this:
Angular ready
Starting $http call
Call finished

The expected output is:
Starting $http call
Call finished
Angular ready

I am running protractor 1.4.0 and I'm currently refactoring my code to upgrade to 1.5. I might have similar issues where the view loaded by ng-route only contains ng-if logic. Protractor is supposed to also wait for this I suppose. I am currently investigating this further, to determine if protractor is also not waiting for this logic.

@0xR
Copy link
Author

0xR commented Dec 18, 2014

Since this issue was marked as needs: investigation I created a minimal application to reproduce the issue. It is available here. See the readme there to reproduce the issue.

@heathkit
Copy link
Contributor

Still a problem, there's a newer issue filed to cover this #2954.

@heathkit
Copy link
Contributor

Actually, doesn't seem like this is a problem anymore. I mapped out all the $apply and $digest cycles around route changes, and even with slowly loading templates protractor consistently does the right thing.

Note that given app is not a valid test - it waits for outstanding requests synchronously, but protractor does all of its waiting asynchronously in webdriver callbacks. However, there is a PR for angular that fixes this issue.

@0xR
Copy link
Author

0xR commented Feb 24, 2016

I disagree that the given app is not a valid test. The main feature of protractor is that you can write your test synchronously and protractor will wait for angular. Or do you mean something else @mgiambalvo?

@juliemr
Copy link
Member

juliemr commented Feb 24, 2016

@0xR The thing about that app is that it's using testability directly, not via Protractor. When Protractor calls whenStable it will be executing the code via WebDriver's executeScript command, which always runs asynchronously.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants