1 package org.itracker.selenium;
2
3 import com.dumbster.smtp.SimpleSmtpServer;
4 import com.dumbster.smtp.SmtpMessage;
5 import org.junit.Test;
6 import org.openqa.selenium.WebDriver;
7
8 import java.util.Timer;
9
10
11
12
13
14
15 public class ForgotPasswordTest extends AbstractSeleniumTestCase {
16
17
18
19
20
21
22
23
24
25
26 @Test
27 public void testIfBothRequired() throws Exception {
28 log.info("running testIfBothRequired");
29 SeleniumManager.closeSession(selenium);
30 selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
31 + applicationPath);
32
33 selenium.click("name=forgotpassword");
34 selenium.waitForPageToLoad(SE_TIMEOUT);
35
36 assertTrue(selenium.isElementPresent("login"));
37 assertTrue(selenium.isElementPresent("lastName"));
38 selenium.click("//input[@type='submit']");
39 selenium.waitForPageToLoad(SE_TIMEOUT);
40
41 assertEquals("Login is required\n Last Name is required",
42 selenium.getText("//span[@class='formError']"));
43 }
44
45
46
47
48
49
50
51
52
53
54 @Test
55 public void testIfLoginRequired() throws Exception {
56 log.info("running testIfLoginRequired");
57 SeleniumManager.closeSession(selenium);
58 selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
59 + applicationPath);
60
61 selenium.click("name=forgotpassword");
62 selenium.waitForPageToLoad(SE_TIMEOUT);
63
64 assertTrue(selenium.isElementPresent("login"));
65 assertTrue(selenium.isElementPresent("lastName"));
66 selenium.type("lastName", "user");
67 selenium.click("//input[@type='submit']");
68 selenium.waitForPageToLoad(SE_TIMEOUT);
69
70 assertEquals("Login is required", selenium.getText("//span[@class='formError']"));
71 }
72
73
74
75
76
77
78
79
80
81
82 @Test
83 public void testIfLastNameRequired() throws Exception {
84 SeleniumManager.closeSession(selenium);
85 selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
86 + applicationPath);
87
88 selenium.click("name=forgotpassword");
89 selenium.waitForPageToLoad(SE_TIMEOUT);
90
91 selenium.type("login", "user");
92 selenium.click("//input[@type='submit']");
93 selenium.waitForPageToLoad(SE_TIMEOUT);
94
95 assertEquals("Last Name is required", selenium.getText("//span[@class='formError']"));
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 @Test
115 public void testRetrievingForgottenPassword() throws Exception {
116 log.info("running testRetrievingForgottenPassword");
117 SeleniumManager.closeSession(selenium);
118 selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
119 + applicationPath);
120
121 final String newPassword;
122
123
124
125 assertElementPresent("name=forgotpassword");
126 selenium.click("name=forgotpassword");
127 selenium.waitForPageToLoad(SE_TIMEOUT);
128 assertElementPresent("login");
129 selenium.type("login", "user_test1");
130 assertElementPresent("lastName");
131 selenium.type("lastName", "user lastname");
132
133 assertElementPresent("//input[@type='submit']");
134
135 selenium.click("//input[@type='submit']");
136 selenium.waitForPageToLoad(SE_TIMEOUT);
137
138
139
140
141
142 assertElementPresent("login");
143 assertElementPresent("password");
144
145
146
147
148
149
150
151
152
153
154
155
156 SeleniumManager.closeSession(selenium);
157 selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
158 + applicationPath);
159 assertElementPresent("login");
160 selenium.type("login", "user_test1");
161 assertElementPresent("password");
162
163
164
165
166
167 }
168
169 @Override
170 protected String[] getDataSetFiles() {
171 return new String[]{
172 "dataset/languagebean_init_dataset.xml",
173 "dataset/languagebean_dataset.xml",
174 "dataset/userpreferencesbean_dataset.xml",
175 "dataset/userbean_dataset.xml"
176 };
177 }
178
179 @Override
180 protected String[] getConfigLocations() {
181 return new String[]{"application-context.xml"};
182 }
183 }