I’ve been wrestling with these lines of Protractor code today:
element(by.linkText("People")).click();
browser.waitForAngular();
var url = browser.getCurrentUrl();
...
It seems that getCurrentUrl
always throws an error when placed after a waitForAngular()
statement.
The error message is rather cryptic:
UnknownError: javascript error: document unloaded while waiting for result
So, how should I correctly click on a link and verify the new url?
Let’s take a look at my test scenarios:
If I call getCurrentUrl()
before clicking on the link,
it('can visit people page', function () {
var url = browser.getCurrentUrl();
element(by.linkText("People")).click();
expect(true).toBe(true);
});
The test will pass without any issues.
However, if I check getCurrentUrl()
after clicking on the link,
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 triggered in Protractor with the UnknownError
message mentioned earlier. Where did I make a mistake?