Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser.navigate().back(); is causing "document unloaded while waiting for result" error #2600

Closed
bmsoko opened this issue Oct 9, 2015 · 7 comments

Comments

@bmsoko
Copy link

bmsoko commented Oct 9, 2015

Hello,
I've read all the questions/answers on the platforms, and none of them helped me to solve my issues, the thing is that I have the following test script:

    it('Verify user sees the home page correctly when hitting back button', function () {
        browser.get('/flight/los-angeles/');
        expect(testUtils.getTextFromField(topSearchBarPage.airportDestLocator)).toContain("LAX");
        element.all(by.css(".day-droppable.ui-droppable")).get(30).click();
        element(by.css(".btn-primary")).click();
        browser.navigate().back();
        expect(browser.getTitle()).toMatch('page title');
        expect(browser.getCurrentUrl()).toContain("/flight/los-angeles/");
    });

And then I'm getting this error:

UnknownError: javascript error: document unloaded while waiting for result

I can see (because I've placed an sleep) that right after executing the navigate.back() the test tries to reload the page, and when it tries to execute the expects, it throws the error.

This is how the app looks like after the navigate.

reload

Please help!

Thanks

@bmsoko bmsoko changed the title browser.navigate().back(); is "causing document unloaded while waiting for result" error browser.navigate().back(); is causing "document unloaded while waiting for result" error Oct 9, 2015
@NickTomlin
Copy link
Contributor

If you can get this in a more isolated/reproducible state let's resubmit it as an issue and work on a fix. I'll try to reproduce this as well. Typically this happens when moving from a synchronized angular state to a non-synchronized one.

That said, I think this is best suited for SO or gitter. Please ask a question there with the 'protractor' tag or post in the Gitter Channel to get help.

@bmsoko
Copy link
Author

bmsoko commented Oct 9, 2015

Thanks @NickTomlin! but I had isolated that the issues here is that method in particular, since I had removed that step (the navigate back) and the expect function works, I had placed a browser.sleep(5000) right after the navigate.back() and that's how I found that it's trying to execute the next "expecs" on an "empty page".
So, how's that you want me to resubmit the issue? I'll join those channels and see if someone can help!

Thanks for the fast reply!

Bruno

@sjelin
Copy link
Contributor

sjelin commented Oct 10, 2015

I'm pretty sure the issue is actually just that element(by.css(".btn-primary")).click(); hasn't finished before browser.navigate().back(); happens. Try adding a browser.waitForAngular().

@sjelin sjelin closed this as completed Oct 10, 2015
@bmsoko
Copy link
Author

bmsoko commented Oct 13, 2015

@sjelin I've tried what you told and it does not work, in fact, the clicking action does happens and finishes when it should since I'm seeing the action being done while the test runs... so, I think that the problem here is the navigate().back() is opening or refreshing without URL, and the next actions are the ones throwing the errors.

Can you please give me a hint to where can I look at to solve this?

Thanks a lot.

Bruno

@bmsoko
Copy link
Author

bmsoko commented Oct 13, 2015

@sjelin @NickTomlin I've just checked using it against Firefox, and the @sjelin's suggestion works! so, the problem is with Chrome! are you aware of any issues around with this with browser? Is there any workaround that you my suggest?

Thanks!!

@sjelin
Copy link
Contributor

sjelin commented Oct 13, 2015

I still think it's a that the click is in some part pending when the navigation happens - that's what the error message says after all. Try:

    it('Verify user sees the home page correctly when hitting back button', function () {
        browser.get('/flight/los-angeles/');
        expect(testUtils.getTextFromField(topSearchBarPage.airportDestLocator)).toContain("LAX");
        element.all(by.css(".day-droppable.ui-droppable")).get(30).click();
        element(by.css(".btn-primary")).click();
        browser.waitForAngular().then(function() {
            browser.navigate().back();
            expect(browser.getTitle()).toMatch('page title');
            expect(browser.getCurrentUrl()).toContain("/flight/los-angeles/");
        });
    });

@leomart
Copy link

leomart commented Oct 19, 2016

Actually, we're facing pretty much the same behavior of browser.navigate().back(); in our tests with only difference in error 'Error: Error while waiting for Protractor to sync with the page: "[ng:test] http://errors.angularjs.org/1.4.7/ng/test"'
Obviously protractor loose synchronization on page reloading (which happens after browser.navigate().back(); in our case).

The code causing error is:

if (button === 'Back') {
            return browser.navigate().back().then(function(){
                return browser.waitForAngular();
            })
        }
    });

or

if (button === 'Back') {
            browser.navigate().back().
            return browser.waitForAngular();
        }

Reproducible on Firefox versions: 43.0.1, node v4.4.3, Protractor 4.0.9
Passes on Chrome.
If we'll add browser.driver.sleep(2000); then the code works as expected, because this tiny delay covers the moment of page reloading and it is enough for Angular to appear on the page:

            return browser.navigate().back().then(function(){
                browser.driver.sleep(2000);
                return browser.waitForAngular();
            })

Stick to that temporary solution by now.

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

No branches or pull requests

4 participants