protractor icon indicating copy to clipboard operation
protractor copied to clipboard

chore(core): Add better error message for client-side redirects

Open sjelin opened this issue 11 years ago • 49 comments

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 avatar Oct 28 '15 19:10 sjelin

@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.

Awk34 avatar Nov 19 '15 21:11 Awk34

If both pages are angular pages, you should just add a browser.refresh after the new page loads to fix the problem

sjelin avatar Nov 19 '15 21:11 sjelin

We're working on a feature to make this better in the future

sjelin avatar Nov 19 '15 21:11 sjelin

I've been struggling with this issue for a week now. browser.refresh() doesn't work if I'm doing a POST.

phillee avatar Dec 07 '15 22:12 phillee

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).

sjelin avatar Dec 08 '15 01:12 sjelin

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 avatar Jan 08 '16 15:01 tassoevan

@tassoevan, that's perfect! It's what I'd expect waitForAngular to do - wait for angular to be available.

phillee avatar Jan 08 '16 15:01 phillee

When protractor starts, it always goes to the baseUrl then my test page. Is that considered the redirect you are talking about?

patrickliechty avatar Feb 11 '16 02:02 patrickliechty

Not quite @patrickliechty, I mean when you click on a link (like <a href='google.com'>) and it directs the browser to google.cm

phillee avatar Feb 14 '16 02:02 phillee

@juliemr with @hankduan gone is there anyone working on the longer term fix for this anymore?

sjelin avatar Feb 16 '16 19:02 sjelin

@sjelin , is this issue still exists in protractor 3.1.1.I can see that one

vivekbrahmadandi avatar Feb 17 '16 10:02 vivekbrahmadandi

+1 for a better fix. Ran into this today with no idea how to reliably work-around it. Thanks!

bobbyg603 avatar Feb 21 '16 23:02 bobbyg603

Having the same Issue!!! thanks @tassoevan for a reliable fix

T3KT4K avatar Feb 23 '16 14:02 T3KT4K

+1 for a fix.

tchaffee avatar Feb 25 '16 17:02 tchaffee

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.

keithdtyler avatar Mar 03 '16 00:03 keithdtyler

I get this error when running against \node_modules\protractor\example\conf.js, surely the example conf.js should always work regardless??

jamestrotter avatar Mar 11 '16 11:03 jamestrotter

For people using Protractor without Angular, is there a workaround ?

Overdrivr avatar Apr 21 '16 17:04 Overdrivr

@Overdrivr You can set browser.ignoreSynchronization = true; to tell Protractor to not wait for Angular.

deltadanger avatar Apr 22 '16 05:04 deltadanger

browser.ignoreSynchronization = true works for me when i switch windows.

adnanghaffar07 avatar May 07 '16 12:05 adnanghaffar07

OK but then U need to set browser.ignoreSynchronization = false;

maciejkamela avatar Jul 15 '16 11:07 maciejkamela