protractor: chore(core): Add better error message for client-side redirects
If the test clicks a link or something which causes a redirect outside of browser.get
or browser.refresh
, then the next time waitForAngular
is called the user will probably run into this error message (since we didn’t wait for Angular to load), which is not very helpful.
Users should be told what’s going wrong and about potential work-arounds (e.g. using browser.get
or browser.refresh
to fix the bootstrapping).
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 20
- Comments: 49 (7 by maintainers)
Commits related to this issue
- chore(error message): make error message for client-side navigation clearer Closes #2643 — committed to sjelin/protractor by sjelin 9 years ago
- chore(error message): make error message for client-side navigation clearer Closes #2643 — committed to sjelin/protractor by sjelin 9 years ago
- add one test Yes, it's irrelevant for us, but it works at least (exit code 0), avoiding the so frustrating error described here : https://github.com/angular/protractor/issues/2643. Maybe some refact... — committed to Iteatime/Acrabadabra by rduthel 5 years ago
- add one test Yes, it's irrelevant for us, but it works at least (exit code 0), avoiding the so frustrating error described here : https://github.com/angular/protractor/issues/2643. Maybe some refact... — committed to Iteatime/Acrabadabra by rduthel 5 years ago
If both pages are angular pages, you should just add a
browser.refresh
after the new page loads to fix the problem@sjelin would you please explain a bit more on what can be done to mitigate this problem?
My use case: I have a test that enters username/password and hits a log in button, that redirects to another page on successful log in.
Actually, I’m using something like this as workaround where I know there will be a redirection:
I have a regular login page and then I redirect to angular page.
So I don’t exactly know how or why it works, because I’m really new to angular and angular e2e, but I got it working once I used the
browser.waitForAngularEnabled(false);
twice.Hope it helps.
@Overdrivr You can set browser.ignoreSynchronization = true; to tell Protractor to not wait for Angular.
I got this error by doing element().getText() outside of the specs (without a browser.get() having occurred) – was trying to create a shortcut for the output of a particular div outside the specs. Turned it into a function and all was well.
@benjaminapetersen - You could try using
waitForAngularEnabled
instead ofignoreSynchronization
. I’m looking at the API reference page for Protractor v5.1.2 and it no longer includesignoreSynchronization
, but looking through the CHANGELOG I don’t see when, if ever, that property was officially deprecated…in angular (2) - Make sure your spec begins w/ browser.get(‘/’);
@tassoevan, that’s perfect! It’s what I’d expect waitForAngular to do - wait for angular to be available.
I’ve been struggling with this issue for a week now.
browser.refresh()
doesn’t work if I’m doing a POST.The solution is “documented” here: https://github.com/angular/protractor/issues/2787
Inside the browser.wait you have to reset ignoreSynchronization. I did this for all the browser.waits where ignoreSynchronization was already true.
My test passes now.
After looking at @tassoevan’s great workaround and getting my redirect tests working, I figured I’d share my TypeScript and Angular2 solution. I put this function on my abstract page class, but I think it might fit better on the
browser
object.Here’s an example of how I used it in a test:
I get this error when running against \node_modules\protractor\example\conf.js, surely the example conf.js should always work regardless??
That last solution almost work for me unless I got an error after the test passes : Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444 From: Task: WebDriver.getCurrentUrl()
rootElement: '*[ng-app]'
? works to just search the page for whatever node? Haven’t seen this before.@thompsnm thanks! Though it looks like waitForAngularEnabled is also deprecated…
I currently get this error when doing the trip to our login page (a common problem):
Doing the
ignoreSync
trick doesn’t seem to help:The link lands here at this thread, but what to do next is not exactly clear.
Tested with Protractor versions: 5.2.1, 5.1.1, 5.1.0, 5.0.0
I realize it’s a lengthy discussion already, but this might help someone.
Such an error message can also happen when the page is reloading unexpectedly because of an unhandled error happening in an Angular component. The fact that browser console may not be persisted, together with how fast the tests execute made it quite not-straightforward for me to understand what was going on.
So maybe something could be done as far as the error message is concerned, since the aforementioned case is not ‘client side navigation’ per se 😃
@azachar this one seems to work:
I don’t know what’s going on, for some reason in this block
ignoreSynchronization
is still false until you force-set it. I followed up in #2787 with this.UPDATE: There are race conditions if you set/reset
ignoreSynchronization
, better put that on control flow. See #4061.OK but then U need to set browser.ignoreSynchronization = false;