protractor icon indicating copy to clipboard operation
protractor copied to clipboard

document unloaded while waiting for result (public version of our angular js in login and actual angular after login)

Open hanssgo opened this issue 13 years ago • 18 comments

So our login has a public version of our angular app and after login, we have the actual angular app.

After login, it never syncs and gives this error UnknownError: javascript error: document unloaded while waiting for result

So my tests after login works with browser.ignoreSynchronization = true;

However, I want to be able to run the tests with synchronization so I do not have to put so many waits. Is there a way around this? Is my suspicion that the reason for my problem is because the public version of our js gets unloaded after login and loads the main app's js?

hanssgo avatar Dec 02 '13 20:12 hanssgo

Can you set ignoreSynchronization to true for the login steps, and then turn it back off for testing the main application?

If that doesn't work, can you show the exact step of your test code where the failure occurs?

juliemr avatar Dec 04 '13 15:12 juliemr

Tried turning ignoreSync to true before doing browser.get and turning it to false after I am in the app. Still hangs =(

    onPrepare:function(){

        browser.get(url);

        login(browser.params.login.user, browser.params.login.password);
        browser.ignoreSynchronization = true;

    }

this is the login function

module.exports = function(username, password){
    var email = element(by.id('inputEmail'));

    helper.wait(email, "Email input");

    email.sendKeys(username);
    element(by.id('inputPassword')).sendKeys(password);
    element(by.css('.btn' )).click()

    browser.sleep(5000);   <--- Hangs after this. Nothing after it gets triggered. Without this browser.sleep, it will give the document unloaded error. 
    helper.wait($('.sidemenu'),"Side Menu");
}

This is my wait function just because its included in the steps i pasted.

exports.wait = function( elm, label ) {
    browser.wait(function(){
        browser.sleep(500);
       if(elm.isPresent()){
           browser.sleep(1000);
           return true;
       }
    },20000, label + " did not load")
}

hanssgo avatar Dec 04 '13 19:12 hanssgo

What's the test output when it hangs? Is it just timing out before the helper.wait call?

juliemr avatar Jan 10 '14 21:01 juliemr

It just gets stuck forever after the login js file is unloaded. No timeout until the script itself gets terminated. On Jan 10, 2014 1:36 PM, "Julie Ralph" [email protected] wrote:

What's the test output when it hangs? Is it just timing out before the helper.wait call?

— Reply to this email directly or view it on GitHubhttps://github.com/angular/protractor/issues/315#issuecomment-32068656 .

hanssgo avatar Jan 10 '14 21:01 hanssgo

Ah! I think I see the problem. Your code in onPrepare will get executed asynchronously - so maybe it's actually trying to run with ignoreSynchronization = false. Where do you turn it back off?

juliemr avatar Jan 10 '14 22:01 juliemr

I turn it ignoresync to true in on prepare and also set to false in on prepare.

So you think I have to set it to true in the first script? Does it have to be before a GET call? On Jan 10, 2014 2:12 PM, "Julie Ralph" [email protected] wrote:

Ah! I think I see the problem. Your code in onPrepare will get executed asynchronously - so maybe it's actually trying to run with ignoreSynchronization = false. Where do you turn it back off?

— Reply to this email directly or view it on GitHubhttps://github.com/angular/protractor/issues/315#issuecomment-32071683 .

hanssgo avatar Jan 10 '14 22:01 hanssgo

Try setting it to 'false' in a beforeEach. You want ignoreSynchronization true for your onPrepare, and false after that, right?

juliemr avatar Jan 10 '14 22:01 juliemr

That's right! let me give it a try. I already have a beforeEach function set up =)

hanssgo avatar Jan 10 '14 22:01 hanssgo

Do i have to do a browser.get after setting ignoreSynchronization=false ? It seems to be getting stuck still even with my current setup.

   onPrepare: function () {
        //Ignore synchronize with the page when the service is communicating with the API
        browser.ignoreSynchronization = true;
        jasmine.getEnv().addReporter(new jasmine.TeamcityReporter());
        //Browse application url
        browser.get(url);
        //Maximize browser window
        browser.manage().window().setSize(1280, 720);
        //browser.manage().window().maximize();  commented out because it was causing the tests to run in mobile mode on build machine
        //User Login
        login(browser.params.login.user, browser.params.login.password);
    }
beforeEach(function() {
    //Ignore synchronize with the page when the service is communicating with the API
    browser.ignoreSynchronization = false;
});

hanssgo avatar Jan 10 '14 22:01 hanssgo

You shouldn't have to do browser.get(). That code looks sane to me, so not sure what's going on anymore. Maybe your wait function? You should be able to simplify to:

exports.wait = function(elm, label) {
    browser.wait(function() {
        return (elm.isPresent());
    }, 20000, label + " did not load")
}

juliemr avatar Jan 10 '14 22:01 juliemr

Heh my wait function on there is actually old and wasn't working :P

It is currently...

exports.wait = function (element, label) {
    browser.wait(function () {
        return element.isPresent().then(function (state) {
            if (state == true) {
                return element.isDisplayed().then(function (state2) {
                    return state2 == true;
                })
            }
            else {
                return false;
            }
        });
    }, 40000, label + " did not load")
    browser.sleep(500);
}

I've had to do a isPresent and isDisplayed because sometimes it is in the DOM but isn't actually on screen yet and tests fail intermittently.

But even if it was the wait function, it would time out eventually and it doesn't. It is just stuck forever. I'll try with your waitfunction though.

hanssgo avatar Jan 10 '14 23:01 hanssgo

Still stuck =( Right after the login.js gets unloaded. It does not sync with the mainapp.js

My onPrepare function

    onPrepare: function () {
        //Ignore synchronize with the page when the service is communicating with the API
        browser.ignoreSynchronization = true;
        //jasmine.getEnv().addReporter(new jasmine.TeamcityReporter());
        //Browse application url
        browser.driver.get(url);
        //Maximize browser window
        browser.manage().window().setSize(1280, 720);
        //browser.manage().window().maximize();  commented out because it was causing the tests to run in mobile mode on build machine
        //User Login
        login(browser.params.login.user, browser.params.login.password);
    }

My Login function

module.exports = function ( username, password ) {
    var emailAddressTextBox = element(by.model('user.Email'));
    var userPasswordTextBox = element(by.model('user.Password'));
    var signInButton = $(".btn");
    var userSideMenuPanel = $(".sidemenu");

    helper.wait ( emailAddressTextBox , "Email input text box" );
    emailAddressTextBox.sendKeys ( username );
    userPasswordTextBox.sendKeys ( password );
    helper.takeScreenshot('login.png');
    click(signInButton, "Sign In Button");
    browser.sleep(4000);
}

beforeEach function

beforeEach(function() {
    //synchronize again with the page 
    browser.ignoreSynchronization = false;

});

stripped down Wait function

exports.wait = function(elm, label){
    browser.wait(function(){
        return (elm.isPresent());
    }, 20000, label + " did not load");
}

stripped down click function

module.exports = function ( element, label, milliseconds) {
    //helper.wait(element, label);
    element.click();
    /*if (typeof milliseconds != 'undefined') {
        browser.sleep(milliseconds);
    }
    else{
        browser.sleep(1000);
    }*/
}

hanssgo avatar Jan 10 '14 23:01 hanssgo

You're sure it makes it out of onPrepare before hanging? If you put a console.log in beforeEach, does that ever get called?

juliemr avatar Jan 11 '14 01:01 juliemr

Yep, it does get into the beforeEach and it does set ignoreSync to false because it proceeds. BUT... nothing passes. all the tests fail with this error:

Timed out waiting for Protractor to synchronize with the page after 11 seconds

hanssgo avatar Jan 13 '14 20:01 hanssgo

Some improvements on debugging have been made - is this still an issue with the latest version?

juliemr avatar Mar 05 '14 05:03 juliemr

Hi Julie,

Yes it is still an issue with the latest version. =(

hanssgo avatar Mar 05 '14 23:03 hanssgo

I'm going through and cleaning up by closing stale questions - sorry for the slow response here, but I think this issue is too out of date to be helpful now. Please re-open if there is a current bug or feature request. If you have a question, consider Stack Overflow.

juliemr avatar Sep 23 '14 17:09 juliemr

Error after calling the plugin method.

 await driver.switchToWebContext();
 await driver.pluginMethod(
      'switch',
      'switchServer()',
    );

javascript error: document unloaded while waiting for result (Session info: chrome=103.0.5060.71)

ERROR webdriver: Request failed with status 500 due to javascript error: javascript error: document unloaded while waiting for result

malisanjay5433 avatar Jun 26 '23 09:06 malisanjay5433