I've got protractor's code written with Jasmine that is supposed to log in the user. Unfortunately there's a redirect going on after going to root url that takes quite some time (about 5 seconds) and I cannot make protractor wait for it. I've already tried browser.wait, I've tried using promises, I've tried with this blogpost, but nothing did it. It still doesn't wait. The login page is a page from Keycloak server, that's why I use driver.findElement instead of element. Here's my current code:
describe('my app', function() {
it('login', function() {
var driver = browser.driver;
browser.get('/');
console.log('get');
driver.findElement(by.id('username')).isPresent().then(function() {
console.log('waited');
driver.findElement(by.id('username')).sendKeys("test");
driver.findElement(by.id('password')).sendKeys("test");
driver.findElement(by.id('kc-login')).click();
driver.findElement(by.css('.page-header')).isPresent().then(function() {
console.log('ok');
expect(browser.getLocationAbsUrl()).toMatch("/test");
});
});
});
});
Do you know what can I do to make it work? I've started protractor project with this seed: https://github.com/angular/angular-seed
You need to turn the synchronization off:
var EC = protractor.ExpectedConditions;
describe('my app', function() {
beforeEach(function () {
browser.ignoreSynchronization = true;
browser.get('/');
});
it('login', function() {
var username = element(by.id('username'));
browser.wait(EC.visibilityOf(username), 10000);
username.sendKeys("test");
element(by.id('password')).sendKeys("test");
element(by.id('kc-login')).click();
var header = element(by.css('.page-header'));
browser.wait(EC.visibilityOf(header), 10000).then(function () {
console.log('logged in');
});
});
});
Note that I've also updated the test: switched back to element and browser, added browser.wait() with built-in Expected Conditions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With