Skip to content

Commit 97e97eb

Browse files
committed
The refactoring for authentication.features for cucumber 0.14 done
1 parent 6f5746d commit 97e97eb

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

tests/cucumber/features/authentication/authentication.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ Feature: Allow user to login and logout
88
Background:
99
Given I am signed out
1010

11-
@rerun
11+
@dev
1212
Scenario: A user can login with valid information
1313
Given I am on the home page
1414
When I click on sign in link
1515
And I enter my authentication information
1616
Then I should be logged in
1717

18-
@rerun
18+
@dev
1919
Scenario: A user cannot login with invalid information
2020
Given I am on the home page
2121
When I click on sign in link
2222
And I enter my false authentication information
2323
Then I should see a user not found error
2424

25-
@rerun
25+
@dev
2626
Scenario: A user cannot login with invalid email address
2727
Given I am on the home page
2828
When I click on sign in link

tests/cucumber/features/authentication/authentication.js

+43-43
Original file line numberDiff line numberDiff line change
@@ -20,83 +20,82 @@
2020
*/
2121

2222
this.Given(/^I am signed out$/, function () {
23-
var client = this.client;
24-
browser.url(process.env.ROOT_URL);
25-
browser.waitForExist(".container");
26-
browser.waitForVisible(".container");
27-
browser.waitForVisible("#login-sign-in-link");
23+
client.url(process.env.ROOT_URL);
24+
client.waitForExist(".container");
25+
client.waitForVisible(".container");
26+
client.waitForVisible("#login-sign-in-link");
2827

29-
actual = browser.getText("#login-sign-in-link");
28+
actual = client.getText("#login-sign-in-link");
3029
expected = "Sign in";
3130

3231
expect(actual).toContain(expected);
3332
});
3433

3534
this.Given(/^I am on the home page$/, function () {
36-
return this.client.
3735
// We navigate into home page
38-
url(process.env.ROOT_URL);
36+
client.url(process.env.ROOT_URL);
3937
});
4038

4139
this.When(/^I click on sign in link$/, function () {
42-
// Wait
43-
var client = this.client;
4440
// We navigate into home page
4541
client.url(process.env.ROOT_URL);
4642

4743
// Wait for the page to load
4844
client.waitForExist(".container", 1000);
49-
client.waitForVisible(".container", 1000)
50-
45+
client.waitForVisible(".container", 1000);
5146
// We click the login button
5247
client.click("#login-sign-in-link");
5348
});
5449

55-
this.When(/^I enter my authentication information$/, function (callback) {
56-
return loginWithCredentials(browser, myEmail, wrongPass);
50+
this.When(/^I enter my authentication information$/, function () {
51+
return loginWithCredentials(browser, myEmail, myPass)
5752
});
5853

59-
this.Then(/^I should be logged in$/, function (callback) {
60-
return this.client.
61-
//We wait if our email address will appear instead of Sign in
62-
waitForExist("#login-name-link", 500).
63-
getText("#login-name-link", function (error, email) {
64-
return chai.expect(email).to.contain(myEmail);
65-
});
54+
this.Then(/^I should be logged in$/, function () {
55+
56+
//We wait if our email address will appear instead of Sign in
57+
client.waitForExist("#login-name-link");
58+
59+
actual = client.getText("#login-name-link");
60+
expected = myEmail;
61+
expect(actual).toContain(expected);
62+
6663
});
6764

6865
/**
6966
* Scenario: A user cannot login with invalid information
7067
*/
7168

7269
this.When(/^I enter my false authentication information$/, function () {
73-
return loginWithCredentials(browser, myEmail, wrongPass);
70+
return loginWithCredentials(browser, wrongEmail, wrongPass);
7471
});
7572

7673
this.Then(/^I should see a user not found error$/, function () {
7774
// We wait the User not found message to appear
78-
return this.client.
79-
waitForExist(".error-message").
80-
getText(".error-message", function (error, message) {
81-
return chai.expect(message).to.contain("User not found");
82-
});
75+
client.waitForExist(".error-message");
76+
77+
actual = client.getText(".error-message");
78+
expected = "User not found";
79+
expect(actual).toContain(expected);
80+
8381
});
8482

8583
/**
8684
* Scenario: A user cannot login with invalid email address
8785
*/
8886

89-
this.When(/^I enter my invalid email address$/, function (callback) {
90-
return loginWithCredentials(browser, myEmail, wrongPass);
87+
this.When(/^I enter my invalid email address$/, function () {
88+
return loginWithCredentials(client, invalidWord, wrongPass);
9189
});
9290

93-
this.Then(/^I should see an invalid email error message$/, function (callback) {
91+
this.Then(/^I should see an invalid email error message$/, function () {
9492
// We wait the Invalid email message to appear
95-
return this.client.
96-
waitForExist(".error-message").
97-
getText(".error-message", function (error, message) {
98-
return chai.expect(message).to.contain("Invalid email");
99-
});
93+
client.waitForExist(".error-message");
94+
95+
actual = client.getText(".error-message");
96+
expected = "Invalid email";
97+
expect(actual).toContain(expected);
98+
10099
});
101100

102101
/**
@@ -105,13 +104,14 @@
105104

106105
this.When(/^I enter my invalid password$/, function () {
107106
// We enter into sign in fields wrong information
108-
return loginWithCredentials(browser, myEmail, wrongPass);
107+
return loginWithCredentials(client, myEmail, wrongPass);
109108
});
110109

111110
this.Then(/^I should see an incorrect password error message$/, function () {
112111
// We wait the Incorrect password message to appear
113-
browser.waitForExist(".error-message");
114-
actual = browser.getText(".error-message");
112+
client.waitForExist(".error-message");
113+
114+
actual = client.getText(".error-message");
115115
expected = "Incorrect password";
116116
expect(actual).toBe(expected);
117117
});
@@ -124,13 +124,13 @@
124124
* @param pass
125125
* @return {*|{phasedRegistrationNames}}
126126
*/
127-
function loginWithCredentials(browser, email, pass) {
128-
browser.waitForExist("#login-email");
127+
function loginWithCredentials(client, email, pass) {
128+
client.waitForExist("#login-email");
129129
// We set the values into email and password
130-
browser.setValue("#login-email", email);
131-
browser.setValue("#login-password", pass);
130+
client.setValue("#login-email", email);
131+
client.setValue("#login-password", pass);
132132

133133
// We click the Sign In button
134-
browser.click('#login-buttons-password')
134+
client.click('#login-buttons-password')
135135
}
136136
})();

tests/cucumber/features/support/hooks.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
'use strict';
44

55
module.exports = function () {
6-
this.Before(function (callback) {
6+
this.Before(function () {
77
// This code runs before every scenario
8-
this.server.call("removePosts");
9-
this.server.call("addInitialPosts");
10-
this.server.call('addUser', {email: "miltos@example.com"});
8+
server.call("removePosts");
9+
server.call("addInitialPosts");
10+
server.call('addUser', {email: "miltos@example.com"});
1111
});
1212
};
1313

0 commit comments

Comments
 (0)