1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.ui; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
|
24 |
|
import org.junit.Assert; |
25 |
|
import org.junit.Before; |
26 |
|
import org.junit.Test; |
27 |
|
import org.openqa.selenium.By; |
28 |
|
import org.openqa.selenium.WebElement; |
29 |
|
import org.openqa.selenium.WebDriverException; |
30 |
|
import org.xwiki.administration.test.po.AdministrationSectionPage; |
31 |
|
import org.xwiki.test.ui.browser.IgnoreBrowser; |
32 |
|
import org.xwiki.test.ui.browser.IgnoreBrowsers; |
33 |
|
import org.xwiki.test.ui.po.AbstractRegistrationPage; |
34 |
|
import org.xwiki.test.ui.po.RegistrationPage; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
|
|
| 96.7% |
Uncovered Elements: 3 (92) |
Complexity: 20 |
Complexity Density: 0.3 |
|
42 |
|
public class RegisterTest extends AbstractTest |
43 |
|
{ |
44 |
|
protected AbstractRegistrationPage registrationPage; |
45 |
|
|
|
|
| 90.9% |
Uncovered Elements: 2 (22) |
Complexity: 3 |
Complexity Density: 0.17 |
|
46 |
21 |
@Before... |
47 |
|
public void setUp() throws Exception |
48 |
|
{ |
49 |
21 |
deleteUser("JohnSmith"); |
50 |
21 |
switchUser(); |
51 |
21 |
this.registrationPage = this.getRegistrationPage(); |
52 |
|
|
53 |
|
|
54 |
21 |
int x = 0; |
55 |
24 |
while (this.registrationPage.isLiveValidationEnabled() != useLiveValidation()) { |
56 |
3 |
AdministrationSectionPage sectionPage = new AdministrationSectionPage("Registration"); |
57 |
3 |
getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(sectionPage.getURL())); |
58 |
3 |
getUtil().recacheSecretToken(); |
59 |
3 |
getUtil().setDefaultCredentials(TestUtils.ADMIN_CREDENTIALS); |
60 |
3 |
getUtil().assertOnPage(sectionPage.getURL()); |
61 |
3 |
sectionPage.getForm().setFieldValue(By.name("XWiki.Registration_0_liveValidation_enabled"), |
62 |
|
Boolean.valueOf(useLiveValidation()).toString()); |
63 |
3 |
sectionPage.clickSave(); |
64 |
3 |
if (x > 2) { |
65 |
0 |
throw new WebDriverException("Unable to set useLiveValidation to " + useLiveValidation()); |
66 |
|
} |
67 |
3 |
x++; |
68 |
3 |
this.registrationPage = this.getRegistrationPage(); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
21 |
getDriver().executeJavascript("document.getElementById('xwikiname').onfocus = null;"); |
74 |
|
|
75 |
21 |
this.registrationPage.fillInJohnSmithValues(); |
76 |
|
} |
77 |
|
|
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
14 |
protected void switchUser()... |
80 |
|
{ |
81 |
|
|
82 |
14 |
getUtil().forceGuestUser(); |
83 |
|
} |
84 |
|
|
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
16 |
protected AbstractRegistrationPage getRegistrationPage()... |
87 |
|
{ |
88 |
16 |
return RegistrationPage.gotoPage(); |
89 |
|
} |
90 |
|
|
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
28 |
protected boolean useLiveValidation()... |
93 |
|
{ |
94 |
28 |
return true; |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
97 |
3 |
@Test... |
98 |
|
@IgnoreBrowsers({ |
99 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
100 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
101 |
|
}) |
102 |
|
public void testRegisterJohnSmith() |
103 |
|
{ |
104 |
3 |
Assert.assertTrue(validateAndRegister()); |
105 |
3 |
tryToLogin("JohnSmith", "WeakPassword"); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
108 |
3 |
@Test... |
109 |
|
@IgnoreBrowsers({ |
110 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
111 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
112 |
|
}) |
113 |
|
public void testRegisterExistingUser() |
114 |
|
{ |
115 |
3 |
registrationPage.fillRegisterForm(null, null, "Admin", null, null, null); |
116 |
|
|
117 |
3 |
Assert.assertFalse(tryToRegister()); |
118 |
3 |
Assert.assertTrue(this.registrationPage.validationFailureMessagesInclude("User already exists.")); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
121 |
3 |
@Test... |
122 |
|
@IgnoreBrowsers({ |
123 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
124 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
125 |
|
}) |
126 |
|
public void testRegisterPasswordTooShort() |
127 |
|
{ |
128 |
3 |
this.registrationPage.fillRegisterForm(null, null, null, "short", "short", null); |
129 |
3 |
Assert.assertFalse(validateAndRegister()); |
130 |
3 |
Assert.assertTrue(this.registrationPage.validationFailureMessagesInclude("Please use a longer password.")); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
133 |
3 |
@Test... |
134 |
|
@IgnoreBrowsers({ |
135 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
136 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
137 |
|
}) |
138 |
|
public void testRegisterDifferentPasswords() |
139 |
|
{ |
140 |
3 |
this.registrationPage.fillRegisterForm(null, null, null, null, "DifferentPassword", null); |
141 |
3 |
Assert.assertFalse(validateAndRegister()); |
142 |
3 |
Assert.assertTrue(this.registrationPage.validationFailureMessagesInclude("The passwords do not match.")); |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
145 |
3 |
@Test... |
146 |
|
@IgnoreBrowsers({ |
147 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
148 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
149 |
|
}) |
150 |
|
public void testRegisterEmptyPassword() |
151 |
|
{ |
152 |
3 |
this.registrationPage.fillRegisterForm(null, null, null, "", "", null); |
153 |
3 |
Assert.assertFalse(validateAndRegister()); |
154 |
3 |
Assert.assertTrue(this.registrationPage.validationFailureMessagesInclude("This field is required.")); |
155 |
|
} |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
157 |
3 |
@Test... |
158 |
|
@IgnoreBrowsers({ |
159 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
160 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
161 |
|
}) |
162 |
|
public void testRegisterEmptyUserName() |
163 |
|
{ |
164 |
|
|
165 |
3 |
this.registrationPage.fillRegisterForm("", "", "", null, null, null); |
166 |
3 |
Assert.assertFalse(validateAndRegister()); |
167 |
3 |
Assert.assertTrue(this.registrationPage.validationFailureMessagesInclude("This field is required.")); |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
170 |
3 |
@Test... |
171 |
|
@IgnoreBrowsers({ |
172 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
173 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
174 |
|
}) |
175 |
|
public void testRegisterInvalidEmail() |
176 |
|
{ |
177 |
3 |
this.registrationPage.fillRegisterForm(null, null, null, null, null, "not an email address"); |
178 |
3 |
Assert.assertFalse(validateAndRegister()); |
179 |
3 |
Assert.assertTrue(this.registrationPage.validationFailureMessagesInclude("Please enter a valid email address.")); |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
187 |
18 |
protected boolean validateAndRegister()... |
188 |
|
{ |
189 |
18 |
if (useLiveValidation()) { |
190 |
12 |
this.registrationPage.triggerLiveValidation(); |
191 |
12 |
if (!this.registrationPage.getValidationFailureMessages().isEmpty()) { |
192 |
10 |
return false; |
193 |
|
} |
194 |
2 |
boolean result = tryToRegister(); |
195 |
|
|
196 |
2 |
Assert.assertTrue("LiveValidation did not show a failure message but clicking on the register button did.", |
197 |
|
this.registrationPage.getValidationFailureMessages().isEmpty()); |
198 |
|
|
199 |
2 |
return result; |
200 |
|
} |
201 |
6 |
return tryToRegister(); |
202 |
|
} |
203 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
204 |
9 |
protected boolean tryToRegister()... |
205 |
|
{ |
206 |
9 |
this.registrationPage.clickRegister(); |
207 |
|
|
208 |
9 |
List<WebElement> infos = getDriver().findElements(By.className("infomessage")); |
209 |
9 |
for (WebElement info : infos) { |
210 |
2 |
if (info.getText().contains("Registration successful.")) { |
211 |
2 |
return true; |
212 |
|
} |
213 |
|
} |
214 |
7 |
return false; |
215 |
|
} |
216 |
|
|
217 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
218 |
21 |
private void deleteUser(final String userName) throws Exception... |
219 |
|
{ |
220 |
21 |
TestUtils.Session s = getUtil().getSession(); |
221 |
21 |
getUtil().forceGuestUser(); |
222 |
21 |
getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(getUtil().getURLToNonExistentPage())); |
223 |
21 |
getUtil().recacheSecretToken(); |
224 |
21 |
getUtil().setDefaultCredentials(TestUtils.ADMIN_CREDENTIALS); |
225 |
21 |
getUtil().rest().deletePage("XWiki", userName); |
226 |
21 |
getUtil().setSession(s); |
227 |
|
} |
228 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
229 |
3 |
protected void tryToLogin(String username, String password)... |
230 |
|
{ |
231 |
|
|
232 |
3 |
getUtil().forceGuestUser(); |
233 |
3 |
getDriver().get(getUtil().getURLToLoginAs(username, password)); |
234 |
3 |
Assert.assertTrue(this.registrationPage.isAuthenticated()); |
235 |
3 |
getUtil().recacheSecretToken(); |
236 |
3 |
getUtil().setDefaultCredentials(username, password); |
237 |
|
} |
238 |
|
} |