Reputation: 16648
Using Angular 5 with Protractor.
Having trouble waiting for the browser url to change to see if the user logs in and then lands on the internal dashboard page.
Spec:
fdescribe('Suite 1', function() {
it('should login and land on the dashboard page', function() {
// Arrange
browser.ignoreSynchronization = true;
const baseUrl = 'confidentialUrl';
const email = 'email';
const password = 'password';
// Act
browser.get(baseUrl);
element(by.id('username')).sendKeys(email);
element(by.id('password')).sendKeys(password);
element(by.css('.submit-btn')).click();
// Assert
browser.wait(5000);
const currentUrl = browser.getCurrentUrl();
expect(currentUrl).toEqual('confidentialUrl/dashboard');
});
Error I get when I do a "protractor conf.js":
Failed: Wait condition must be a promise-like object, function, or a Condition object
Upvotes: 0
Views: 400
Reputation: 5836
browser.wait
requires an object as a first parameter which is condition object or promise-like object. For example you can create an expected condition from protractor
// Expected condition object
const EC = protractor.ExpectedConditions;
// wait 5 seconds for expected condition
// in this case it will wait for url contains a given value
browser.wait(EC.urlContains('foo'), 5000).then(() => {
// then you can assert here
const currentUrl = browser.getCurrentUrl();
return expect(currentUrl).toEqual('confidentialUrl/dashboard');
});
We resolved this kind of problems with using ExpectedConditions.
I edited your code, so in your case:
fdescribe('Suite 1', function() {
it('should login and land on the dashboard page', function() {
// Arrange
browser.ignoreSynchronization = true;
const baseUrl = 'confidentialUrl';
const email = 'email';
const password = 'password';
// Act
browser.get(baseUrl);
element(by.id('username')).sendKeys(email);
element(by.id('password')).sendKeys(password);
element(by.css('.submit-btn')).click();
// Assert
const EC = protractor.ExpectedConditions;
browser.wait(EC.urlContains('confidentialUrl/dashboard'), 5000).then(() => {
const currentUrl = browser.getCurrentUrl();
return expect(currentUrl).toEqual('confidentialUrl/dashboard');
})
});
or you can:
fdescribe('Suite 1', function() {
it('should login and land on the dashboard page', function() {
// Arrange
browser.ignoreSynchronization = true;
const baseUrl = 'confidentialUrl';
const email = 'email';
const password = 'password';
// Act
browser.get(baseUrl);
element(by.id('username')).sendKeys(email);
element(by.id('password')).sendKeys(password);
element(by.css('.submit-btn')).click();
// Assert
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return expect(url).toEqual('confidentialUrl/dashboard');
});
}, 10000);
});
Upvotes: 1