Skip to content

Commit 239f412

Browse files
author
PinkyJie
committed
add e2e test for login page
1 parent b20f244 commit 239f412

File tree

4 files changed

+123
-4
lines changed

4 files changed

+123
-4
lines changed

app/templates/client/source/app/login/login.jade

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
lx-text-field(label="Password", fixed-label="true", icon="key")
1414
input(type="password", ng-model="vm.credential.password", required)
1515
.card__actions.text-center(class="p+")
16-
button.btn.btn--l.btn--blue.btn--raised(type="submit",
16+
button.btn.btn--l.btn--blue.btn--raised.btn-login(type="submit",
1717
ng-disabled="vm.loginForm.$invalid || vm.isRequest",
1818
ng-class="{'btn--is-disabled': vm.loginForm.$invalid}",
1919
lx-ripple,

app/templates/client/source/test/e2e/helper.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module.exports = function () {
55
return {
66
gotoUrl: gotoUrl,
77
getHeader: getHeader,
8-
takeScreenshotIfFail: takeScreenshotIfFail
8+
takeScreenshotIfFail: takeScreenshotIfFail,
9+
waitForPromiseTest: waitForPromiseTest,
10+
expectUrlToMatch: expectUrlToMatch
911
};
1012

1113
//////////
@@ -43,4 +45,19 @@ module.exports = function () {
4345
});
4446
}
4547
}
48+
49+
function waitForPromiseTest (promiseFn, testFn) {
50+
browser.wait(function () {
51+
var deferred = protractor.promise.defer();
52+
promiseFn.then(function (data) {
53+
deferred.fulfill(testFn(data));
54+
});
55+
return deferred.promise;
56+
}, browser.params.timeout);
57+
}
58+
59+
function expectUrlToMatch (url) {
60+
expect(browser.getCurrentUrl()).toMatch(new RegExp(url));
61+
}
62+
4663
};

app/templates/client/source/test/e2e/specs/home.spec.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var HomePage = function () {
77

88
self.url = '';
99
self.ele = _getAllElements();
10+
1011
self.load = load;
1112

1213
////////
@@ -27,7 +28,7 @@ var HomePage = function () {
2728
}
2829
};
2930

30-
module.exports = HomePage;
31+
module.exports = new HomePage();
3132

3233
// test scenarios
3334
describe('Home Page:', function () {
@@ -54,7 +55,7 @@ describe('Home Page:', function () {
5455

5556
it('should go to login page if click get started', function () {
5657
page.ele.getStartedBtn.click();
57-
expect(browser.getCurrentUrl()).toMatch(/login/);
58+
browser._.expectUrlToMatch('login');
5859
});
5960

6061
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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

Comments
 (0)