i'm currently learning to write tests using protractor and i'm stuck and unable to understand the proper way to write a simple login/logout test.
describe('Login with dummy user', function () {
browser.ignoreSynchronization = true;
browser.get('https://localhost:44311');
element(by.id('userNameInput')).sendKeys('blabla');
element(by.id('passwordInput')).sendKeys('blablapassword');
element(by.id('submitButton')).click();
browser.ignoreSynchronization = false;
browser.sleep(2000);
it('page should have Inventory title', function () {
expect(browser.getTitle()).toEqual('Inventory');
});
it(' page should have logout button', function () {
var completedAmount = element.all(by.css('.logoutButton'));
expect(completedAmount.count()).toEqual(1);
});
describe('clicking loging out button', function () {
browser.sleep(2000);
element(by.css('[href="/account/signout"]')).click();
it('should redirect to account page', function () {
expect(browser.getCurrentUrl()).toEqual('https://localhost:44311/account');
});
it('should display a signed out message', function () {
expect(element(by.css('text-success')).getText()).toEqual('You have successfully signed out');
});
});
});
I expect that the first two it would run before the second describe, but the browser clicks the button, logouts, browser closes and only then do the tests run and fail.
it
inside yourit
. You can't keep anything outsideit
blocks, so moveelement(by.id('userNameInput')).sendKeys('blabla');
and other to yourit
– FCinit
should test what it has in its description. If you have to make couple of expects, you can. – FCinPage Object Pattern
for protractor. It really helps. – FCin