Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavascriptError: javascript error: document unloaded while waiting for result

While testing angular apps using protractor e2e test runs.

I am currently facing a problem. And its an intermittent issue. I am receiving “JavascriptError: javascript error: document unloaded while waiting for result ” .

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

I think it does mean here that before expect finishes it's assertion, the page being targeted is no more available or unloaded.

So, after every page navigation, I tried adding "browser.waitForAngular()". But it did't help the assertion to pass.

Curious thing is that same test pass in Ubuntu14.04 platform but fails in Mac OS X 10.10.4 x86_64

It doesn't fail for the same test every time. It's always a different test.

Any advise would be really helpful.

Thanks.

like image 640
Gaurav Tandon Avatar asked Aug 13 '15 22:08

Gaurav Tandon


1 Answers

I was able to fix this issue by making browser sleep for few seconds after every change in URL.

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.sleep(2000);
.        expect(browser.getCurrentUrl()).toEqual(vacanciesUrl);
.        vacanciesPage = new VacanciesPage();
.        vacanciesPage.addVacancyButton.click();
.
.

I don't think this is a neat solution to this problem.

I will be happy to hear, if someone has a better solution to this.

Cheers Gaurav

like image 127
Gaurav Tandon Avatar answered Oct 23 '22 05:10

Gaurav Tandon