I'm using webdriverio v4 and chai to enter values into a login form, click the login button and verify the navigated to URL:
describe('login form', function () {
it('should allow access with correct credentials', function () {
LoginPage.open();
LoginPage.username.setValue('name');
LoginPage.companyCode.setValue('100');
LoginPage.password.setValue('password');
LoginPage.loginButton.click();
expect(browser.getUrl()).to.equal('URL path');
});
});
the values are entered successfully and the expected URL is navigated to. However, browser.getURL() is returning the base URL rather than the new URL?
What am I doing wrong?
The URL may be retrieved too quickly. You may have to wait until the page has loaded the new page before getting the URL.
Could use something like with waitUntil
and check the URL within the callback. Like so:
browser.waitUntil(function() {
return browser.getUrl() === urlToCheck;
}, 5000);