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).
@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.
If both pages are angular pages, you should just add a browser.refresh after the new page loads to fix the problem
We're working on a feature to make this better in the future
I've been struggling with this issue for a week now. browser.refresh() doesn't work if I'm doing a POST.
That's good to keep in mind, thanks. For now, you could probably mitigate the problem by just having your test wait a few hundred milliseconds after the client side redirect occurs. This will stop Protractor from throwing the error message, though it wouldn't allow Protractor to bootstrap properly so it may cause some other unexpected problems (especially if you're using plugins or mock modules).
Actually, I'm using something like this as workaround where I know there will be a redirection:
(function (expectedUrl, timeout) {
var loaded = false;
browser.wait(function () {
browser.executeScript(function () {
return {
url: window.location.href,
haveAngular: !!window.angular
};
}).then(function (obj) {
loaded = (obj.url == expectedUrl && obj.haveAngular);
});
return loaded;
}, timeout);
})(expectedUrl, timeout);
@tassoevan, that's perfect! It's what I'd expect waitForAngular to do - wait for angular to be available.
When protractor starts, it always goes to the baseUrl then my test page. Is that considered the redirect you are talking about?
Not quite @patrickliechty, I mean when you click on a link (like <a href='google.com'>) and it directs the browser to google.cm
@juliemr with @hankduan gone is there anyone working on the longer term fix for this anymore?
@sjelin , is this issue still exists in protractor 3.1.1.I can see that one
+1 for a better fix. Ran into this today with no idea how to reliably work-around it. Thanks!
Having the same Issue!!! thanks @tassoevan for a reliable fix
+1 for a fix.
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.
I get this error when running against \node_modules\protractor\example\conf.js, surely the example conf.js should always work regardless??
For people using Protractor without Angular, is there a workaround ?
@Overdrivr You can set browser.ignoreSynchronization = true; to tell Protractor to not wait for Angular.
browser.ignoreSynchronization = true works for me when i switch windows.
OK but then U need to set browser.ignoreSynchronization = false;