Protractor: UnknownError: javascript error: document unloaded while waiting for result

Created on 4 Sep 2014  ·  9Comments  ·  Source: angular/protractor

Hello I have a problem with “UnknownError: javascript error: document unloaded while waiting for result ” . The error appears in all sets of tests where the login to the site. At every the third or fourth launch. Failed always the first test using the login(); function. So I use a special test to work around this. But it is never been beautiful solution. First page of Google on request: "UnknownError: javascript error: document unloaded while waiting for result", did not help.
What can I do with this?

The necessary information:
Log of error:

UnknownError: javascript error: document unloaded while waiting for result 
(Session info: chrome=36.0.1985.143) 
(Driver info: chromedriver=2.10.267521,platform=Windows NT 6.3 x86_64)
 (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 3.27 seconds 
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03' System info:  os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.7.0_67' 
Driver info: org.openqa.selenium.chrome.ChromeDriver 
Capabilities 
  [{platform=WIN8_1, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, 
  chrome={userDataDir=C:\%UserAppData%\Local\Temp\scoped_dir4736_31820}, 
  rotatable=false, locationContextEnabled=true, version=36.0.1985.143, 
  takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, 
  handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, 
  webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]
     at new bot.Error (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:109:18)
     at Object.bot.response.checkResponse (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:106:9)
     at C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:277:20 
     at C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:1243:15
     at webdriver.promise.ControlFlow.runInNewFrame_ (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1539:20)
     at notify (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:362:12)
     at notifyAll (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:331:7)
     at resolve (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:309:7)
     at fulfill (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:429:5)
     at C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1406:10
 ==== async task ====
     WebDriver.executeScript() 
     at webdriver.WebDriver.schedule (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:268:15)
     at webdriver.WebDriver.executeAsyncScript (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:496:15)
     at Protractor.waitForAngular (C:\%UserAppData%\Roaming\npm\node_modules\protractor\lib\protractor.js:887:22)
     at login (C:\%ProjectFolder%\E2E-test\support\LoginPage.js:13:17)
     at null. (C:\%ProjectFolder%\E2E-test\spec\Login page\signin.js:12:47)
     at C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:94:14
     at webdriver.promise.ControlFlow.runInNewFrame_ (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1539:20)
     at webdriver.promise.ControlFlow.runEventLoop_ (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1404:8)
     at wrapper [as _onTimeout] (timers.js:261:14) 
 ==== async task ==== 
     Asynchronous test function: it()
     at null. (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:93:33)
     at null. (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js:45:37)
     at jasmine.Block.execute (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1174:17)
     at jasmine.Queue.next_ (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31)
     at null._onTimeout (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2199:18)
     at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
 ==== async task ==== 
     Error 
     at null. (C:\%ProjectFolder%\E2E-test\spec\Login page\signin.js:12:5)
     at jasmine.Env.describe_ (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21)
     at jasmine.Env.describe (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15)
     at describe (C:\%UserAppData%\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27)
     at Object. (C:\%ProjectFolder%\E2E-test\spec\Login page\signin.js:5:1)
     at Module._compile (module.js:456:26)
     at Object.Module._extensions..js (module.js:474:10)
     at Module.load (module.js:356:32)
     at Function.Module._load (module.js:312:12)

E2E-test\protractor.conf.js

//https://github.com/jintoppy/protractor-html-screenshot-reporter
var HtmlReporter = require('protractor-html-screenshot-reporter'),
    FileSystem = require('fs');

exports.config =
{
    seleniumAddress: 'http://localhost:4444/wd/hub',

    suites: {
        specs: __dirname + '/spec/**/*.js',
        login: __dirname + '/spec/Login page/*.js',
    },

    baseUrl:'http://localhost:5555/', 

    params: 
    {
        login: 
        {
            user: 'login',
            password: 'password'
        },
        basePath: __dirname,
        baseUrl:'http://localhost:5555/'
    },
    onPrepare: function () 
    {
        browser.driver.manage().window().maximize();
        jasmine.getEnv().addReporter(
            new HtmlReporter(
                        {
                baseDirectory: __dirname + '/result'
            }));
    },

    capabilities: 
    { 
        browserName : 'chrome',
        'chromeOptions': 
                {
            args: ['--test-type']                   
        }
    },

    allScriptsTimeout: 30000
};

E2E-test\spec\Login page\signin.js:

var basePath = browser.params.basePath;
var baseUrl = browser.params.baseUrl;
var loginPage = require(basePath + '/support/LoginPage.js');

describe('Login page; login tests:', function ()
{   
    beforeEach(function() 
    {
        browser.get('#/login');     
        browser.waitForAngular();   
    });                             

    it('Failed test', function ()
    { 
        loginPage.login(browser.params.login.user, browser.params.login.password);
        browser.waitForAngular();
    }, 10000);

    it('Try input invavid login format', function () 
    {
        loginPage.userName.clear();                                                                
        loginPage.userName.sendKeys('InvalidNameFormat');                                         
        expect(element.all(by.css('span[class*="error"]')).get(0).isDisplayed()).toBe(true);      
    }, 10000);        

   //Several similar tests

    it('Try input correct login/password', function () 
    {
        loginPage.login(browser.params.login.user, browser.params.login.password);
        browser.waitForAngular();
        expect(browser.getCurrentUrl()).toContain('#/branches');
    }, 10000);
});

E2E-test\support\LoginPage.js:

var LoginPage = function() 
{
    this.userName = element(by.id('email'));
    this.userPassword = element(by.id('password'));
    this.forgotPasswordButton = element(by.css('[ng-href*="reset"]'));
    this.submitButton = element.all(by.css('[type="submit"]')).get(0);

    this.login = function(userName, password) 
    {
        element(by.id('email')).clear();
        element(by.id('email')).sendKeys(userName);
        element(by.id('password')).clear();
        element(by.id('password')).sendKeys(password);
        element.all(by.css('[type="submit"]')).get(0).click();
        browser.waitForAngular();
    }
};

module.exports = new LoginPage();
question

Most helpful comment

I think the problem is the last browser.waitForAngular call in LoginPage.login. Your website is loading a new page after clicking the submit button. waitForAngular is interrupted, since it's a js function and webdriver throws that error when a new page is loaded as it's trying to execute a js function.

Can you replace that with some other proxy to ensure that login has succeeded? See https://github.com/angular/protractor/blob/master/spec/withLoginConf.js for an example.

All 9 comments

I think the problem is the last browser.waitForAngular call in LoginPage.login. Your website is loading a new page after clicking the submit button. waitForAngular is interrupted, since it's a js function and webdriver throws that error when a new page is loaded as it's trying to execute a js function.

Can you replace that with some other proxy to ensure that login has succeeded? See https://github.com/angular/protractor/blob/master/spec/withLoginConf.js for an example.

Thank you, it helped.

I am facing right now a similar kind of issue. Any advise would be really helpful.
Curious thing is that same test pass in Ubuntu14.04 platform
but fails in Mac OS X 10.10.4 x86_64

And its an intermittent issue.
It doesn't fail for the same test every time. It's always a different test.

Below are logs:

Failures:
[18:51:46][Step 4/4] 1) vacancies should create new job listing
[18:51:46][Step 4/4]   Message:
[18:51:46][Step 4/4]  [31m    Failed: javascript error: document unloaded while waiting for result
[18:51:46][Step 4/4]       (Session info: chrome=44.0.2403.155)
[18:51:46][Step 4/4]       (Driver info: chromedriver=2.15.322455 (rg5th540dac8d0c453355d3d922c91ads1231),platform=Mac OS X 10.10.4 x86_64) [0m
[18:51:46][Step 4/4]   Stack:
[18:51:46][Step 4/4]     JavascriptError: javascript error: document unloaded while waiting for result
[18:51:46][Step 4/4]       (Session info: chrome=44.0.2403.155)
[18:51:46][Step 4/4]       (Driver info: chromedriver=2.15.322455 (rg5th540dac8d0c453355d3d922c91ads1231),platform=Mac OS X 10.10.4 x86_64)
[18:51:46][Step 4/4]         at Array.forEach (native)
[18:51:46][Step 4/4]     From: Task: Run it("should create new job listing") in control flow
[18:51:46][Step 4/4]         at Array.forEach (native)
[18:51:46][Step 4/4]     From asynchronous test: 
[18:51:46][Step 4/4]     Error
[18:51:46][Step 4/4]         at Suite.<anonymous> (/client/test/e2e/vacancies/vacancies.create.specs.js:67:7)
[18:51:46][Step 4/4]         at Object.<anonymous> (/client/test/e2e/vacancies/vacancies.create.specs.js:17:3)

The lines that the log is pointing to is the test's starting line.

Below is the code snippet:

67 it('should create new job listing', function () {
68        //Login As Admin To Access Vacancies Feature
69        loginAsManager();
.
.        //load manager's dashboard list page
.        dashboardPage = new DashboardPage();
.        dashboardPage.vacanciesTab.click();
.
.        //load vacancies list page
.        var vacanciesUrl = browser.baseUrl + '#/vacancies';
.        browser.waitForAngular();
.        expect(browser.getCurrentUrl()).toEqual(vacanciesUrl);
.        vacanciesPage = new VacanciesPage();
.        vacanciesPage.addVacancyButton.click();
.
.

Hi! I'm having the same issues, but the difference that I have, is that I'm not using the browser.waitForAngular... I had identified that these two steps are the one that are causing the problem

        expect(browser.getTitle()).toEqual('Page Title');
        expect(browser.getCurrentUrl()).toContain("/some/url/");

Which could be the reason of this? can you please assist?

Thanks

EDIT: Just happens on chrome.

@juliemr, I followed your proxy example to the letter, however, I had varying results. Typically the first test failed. I ended up adding a browser.sleep(3000) after the click and now things work consistently. Three seconds was my magic number, two seconds didn't work.

@dandoyon Faced same issue today, browser.sleep(2000) worked.

Im facing this issue right now, and it's completely intermittent. Using browser.sleep(2000) works well, but it's a neat solution. I'm still looking for a better solution to this, do somebody have any tip?

PS: I tried a lot of things, e.g: waiting for the correct url before clicking button, using expectedConditions.visibilityOf(), expectedConditions.presenceOf(), adding click button in control flow, changed defaultTimeoutInterval, and nothing works.

Here is the error:
Failed: javascript error: document unloaded while waiting for result
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.11.6 x86_64) (WARNING: The server did not provide any stacktrace information)

In my instance of seeing this today it was due to waitForAngular when the host died due to a bad method call; so, dev issue on the ui side, not a protractor problem; glad this error bubbled up.

Yeah, Protractor does a lot of waitForAngular calls. If the page crashes, the browser closes, or the app navigates to a different URL for some reason, you might see this error. But it would be the result of a different problem that happened to occur while a waitForAngular call was in flight.

Was this page helpful?
0 / 5 - 0 ratings