Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  53] [ 5]  / answers: 1 / hits: 25735  / 9 Years ago, wed, march 18, 2015, 12:00:00

I have been struggling with these lines of Protractor code today:



element(by.linkText(People)).click();
browser.waitForAngular();
var url = browser.getCurrentUrl();
...


It appears that getCurrentUrl always fails when placed after a waitForAngular() statement.



The error output is too vague:




UnknownError: javascript error: document unloaded while waiting for result




So, what is the correct way to click on a hyperlink and check the new url?






Here are my tests:



If I getCurrentUrl() before the link is clicked,



it('can visit people page', function () {
var url = browser.getCurrentUrl();
element(by.linkText(People)).click();
expect(true).toBe(true);
});


The test will pass.



If I getCurrentUrl() after the link is clicked,



it('can visit people page', function () {
var url = browser.getCurrentUrl();
element(by.linkText(People)).click();
expect(true).toBe(true);
url = browser.getCurrentUrl();
});


An error is thrown in Protractor with the UnknownError output above. What went wrong?


More From » angularjs

 Answers
42

Instead of waitForAngular() call, wait for the URL to change:



browser.wait(function() {
return browser.getCurrentUrl().then(function(url) {
return /index/.test(url);
});
}, 10000, URL hasn't changed);


Originally suggested by @juliemr at UnknownError: javascript error: document unloaded while waiting for result.


[#67392] Monday, March 16, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josiah

Total Points: 208
Total Questions: 105
Total Answers: 107

Location: Seychelles
Member since Mon, Jun 28, 2021
3 Years ago
;