|
| 1 | +/* global $ */ |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +// page object |
| 5 | +var LoginPage = function () { |
| 6 | + var self = this; |
| 7 | + |
| 8 | + self.url = 'login'; |
| 9 | + self.ele = _getAllElements(); |
| 10 | + self.urlAfterLogin = 'dashboard'; |
| 11 | + self.logoutUrl = 'login?action=logout'; |
| 12 | + |
| 13 | + self.load = load; |
| 14 | + self.loginWithCredential = loginWithCredential; |
| 15 | + |
| 16 | + //////// |
| 17 | + |
| 18 | + function _getAllElements () { |
| 19 | + return { |
| 20 | + 'loadingView': $('.login-checking'), |
| 21 | + 'loadingIcon': $('.login-checking > .mdi-sync'), |
| 22 | + 'accountIcon': $('.login-checking > .mdi-account'), |
| 23 | + 'loadingText': $('.login-checking > .loading-text'), |
| 24 | + 'loginMessage': $('.login-message > p'), |
| 25 | + 'emailInput': element(by.model('vm.credential.email')), |
| 26 | + 'passwordInput': element(by.model('vm.credential.password')), |
| 27 | + 'loginBtn': $('.btn-login') |
| 28 | + }; |
| 29 | + } |
| 30 | + |
| 31 | + function load () { |
| 32 | + browser._.gotoUrl(self.url); |
| 33 | + } |
| 34 | + |
| 35 | + function loginWithCredential (email, password) { |
| 36 | + self.ele.emailInput.sendKeys(email); |
| 37 | + self.ele.passwordInput.sendKeys(password); |
| 38 | + expect(self.ele.loginBtn.isEnabled()).toBe(true); |
| 39 | + self.ele.loginBtn.click(); |
| 40 | + } |
| 41 | +}; |
| 42 | + |
| 43 | +module.exports = new LoginPage(); |
| 44 | + |
| 45 | +// test scenarios |
| 46 | +describe('Login Page:', function () { |
| 47 | + var page; |
| 48 | + beforeEach(function () { |
| 49 | + page = new LoginPage(); |
| 50 | + page.load(); |
| 51 | + }); |
| 52 | + |
| 53 | + afterEach(function () { |
| 54 | + browser._.takeScreenshotIfFail(); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should login successfully with correct credential', function () { |
| 58 | + expect(page.ele.loginBtn.isEnabled()).toBe(false); |
| 59 | + page.loginWithCredential('f@f', 'f'); |
| 60 | + browser._.expectUrlToMatch(page.urlAfterLogin); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should display error message with incorrect credential', function () { |
| 64 | + expect(page.ele.loginMessage.isPresent()).toBe(false); |
| 65 | + page.loginWithCredential('[email protected]', 'f'); |
| 66 | + expect(page.ele.loginMessage.isDisplayed()).toBe(true); |
| 67 | + expect(page.ele.loginMessage.getText()) |
| 68 | + .toEqual('Incorrect email or password, please try again!'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should display error message with locked account', function () { |
| 72 | + expect(page.ele.loginMessage.isPresent()).toBe(false); |
| 73 | + page.loginWithCredential('[email protected]', 'f'); |
| 74 | + expect(page.ele.loginMessage.isDisplayed()).toBe(true); |
| 75 | + expect(page.ele.loginMessage.getText()) |
| 76 | + .toEqual('Your account is locked!'); |
| 77 | + }); |
| 78 | + |
| 79 | +}); |
| 80 | + |
| 81 | +describe('Logout Page:', function () { |
| 82 | + var page; |
| 83 | + beforeEach(function () { |
| 84 | + page = new LoginPage(); |
| 85 | + browser._.gotoUrl(page.logoutUrl); |
| 86 | + }); |
| 87 | + |
| 88 | + afterEach(function () { |
| 89 | + browser._.takeScreenshotIfFail(); |
| 90 | + }); |
| 91 | + |
| 92 | + it('should not display loading view', function () { |
| 93 | + expect(page.ele.loadingView.isPresent()).toBe(false); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should display success logout message', function () { |
| 97 | + expect(page.ele.loginMessage.isDisplayed()).toBe(true); |
| 98 | + expect(page.ele.loginMessage.getText()) |
| 99 | + .toEqual('You have been successfully logged out!'); |
| 100 | + }); |
| 101 | +}); |
0 commit comments