This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
RegisterTest.java
236 lines (199 loc) · 8.82 KB
/
RegisterTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.feature.account;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.Feature;
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.feature.testharness.TestPlan.BasicAcceptanceTest;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.page.account.RegisterPage;
import org.zanata.page.account.SignInPage;
import org.zanata.page.utility.HomePage;
import org.zanata.util.AddUsersRule;
import org.zanata.util.HasEmailRule;
import org.zanata.workflow.BasicWorkFlow;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Damian Jansen <a
* href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
@Category(DetailedTest.class)
public class RegisterTest extends ZanataTestCase {
@ClassRule
public static AddUsersRule addUsersRule = new AddUsersRule();
@ClassRule
public static HasEmailRule emailRule = new HasEmailRule();
Map<String, String> fields;
private HomePage homePage;
@Before
public void before() {
// fields contains a set of data that can be successfully registered
fields = new HashMap<String, String>();
// Conflicting fields - must be set for each test function to avoid
// "not available" errors
fields.put("email", "test@example.com");
fields.put("username", "testusername");
fields.put("name", "test");
fields.put("password", "testpassword");
homePage = new BasicWorkFlow().goToHome();
homePage.deleteCookiesAndRefresh();
}
@Feature(summary = "The user can register an account with Zanata",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 86816)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
@Category(BasicAcceptanceTest.class)
public void registerSuccessful() throws Exception {
RegisterPage registerPage = homePage
.goToRegistration()
.setFields(fields);
assertThat(registerPage.getErrors())
.as("No errors are shown")
.isEmpty();
homePage = registerPage.register();
assertThat(homePage.getNotificationMessage())
.isEqualTo(HomePage.SIGNUP_SUCCESS_MESSAGE)
.as("Sign up is successful");
}
@Feature(summary = "The user must enter a username of between 3 and " +
"20 (inclusive) characters to register",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void usernameLengthValidation() throws Exception {
fields.put("email", "length.test@example.com");
RegisterPage registerPage = homePage.goToRegistration();
fields.put("username", "bo");
registerPage = registerPage.setFields(fields);
assertThat(containsUsernameError(registerPage.getErrors()))
.isTrue()
.as("Size errors are shown for string too short");
fields.put("username", "testusername");
registerPage = registerPage.setFields(fields);
assertThat(containsUsernameError(registerPage.getErrors()))
.isFalse()
.as("Size errors are not shown");
fields.put("username", "12345678901234567890a");
registerPage = registerPage.setFields(fields);
assertThat(containsUsernameError(registerPage.getErrors()))
.isTrue()
.as("Size errors are shown for string too long");
}
@Feature(summary = "The user must enter a unique username to register",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void usernamePreExisting() throws Exception {
RegisterPage registerPage = homePage
.goToRegistration()
.enterUserName("admin");
registerPage.defocus(registerPage.usernameField);
assertThat(registerPage.getErrors())
.contains(RegisterPage.USERNAME_UNAVAILABLE_ERROR)
.as("Username not available message is shown");
}
@Feature(summary = "The user must enter all necessary fields to register",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
@Ignore("RHBZ-1024150")
public void requiredFields() throws Exception {
fields.put("name", "");
fields.put("username", "");
fields.put("email", "");
fields.put("password", "");
RegisterPage registerPage =
homePage.goToRegistration().setFields(fields);
registerPage.defocus();
assertThat(registerPage.getErrors(4)).containsExactly(
RegisterPage.REQUIRED_FIELD_ERROR,
RegisterPage.USERNAME_VALIDATION_ERROR,
RegisterPage.REQUIRED_FIELD_ERROR,
RegisterPage.REQUIRED_FIELD_ERROR)
.as("Value is required shows for all fields");
}
@Feature(summary = "The user can access the login page from the register " +
"page, and vice versa",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test
public void signUpToLoginAndBack() {
RegisterPage registerPage = new BasicWorkFlow()
.goToHome()
.clickSignInLink()
.goToRegister();
assertThat(registerPage.getPageTitle())
.isEqualTo("Sign up with Zanata")
.as("The user is sent to the register page");
SignInPage signInPage = registerPage.goToSignIn();
assertThat(signInPage.getPageTitle())
.isEqualTo("Log in with your username")
.as("The user is sent to the log in page");
}
@Feature(summary = "The user can toggle the entered password visible and " +
"masked",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test
public void togglePasswordVisible() {
RegisterPage registerPage = new BasicWorkFlow()
.goToHome()
.goToRegistration()
.enterPassword("mypassword");
assertThat(registerPage.getPasswordFieldType())
.isEqualTo("password")
.as("The password field starts as masked");
registerPage = registerPage.clickPasswordShowToggle();
assertThat(registerPage.getPasswordFieldType())
.isEqualTo("text")
.as("The password field is now not masked");
registerPage = registerPage.clickPasswordShowToggle();
assertThat(registerPage.getPasswordFieldType())
.isEqualTo("password")
.as("The password field is again masked");
assertThat(registerPage.getPassword())
.isEqualTo("mypassword")
.as("The password field did not lose the entered text");
}
@Feature(summary = "The user must enter at least one alphanumeric " +
"character in their username",
bugzilla = 981498)
@Test
public void bug981498_underscoreRules() {
fields.put("email", "bug981498test@example.com");
fields.put("username", "______");
RegisterPage registerPage =
homePage.goToRegistration().setFields(fields);
registerPage.defocus();
assertThat(registerPage.getErrors())
.contains(RegisterPage.USERNAME_VALIDATION_ERROR)
.as("A username of all underscores is not valid");
}
/*
* Helper function - the error returned may be different depending on
* the given input.
*/
private boolean containsUsernameError(List<String> errors) {
return errors.contains(RegisterPage.USERNAME_VALIDATION_ERROR) ||
errors.contains(RegisterPage.USERNAME_LENGTH_ERROR);
}
}