1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.samplu.common;
17
18 import com.thoughtworks.selenium.Selenium;
19 import org.junit.After;
20 import org.junit.Assert;
21 import org.junit.Before;
22 import org.openqa.selenium.NoSuchFrameException;
23 import org.openqa.selenium.WebDriver;
24 import org.openqa.selenium.WebDriverBackedSelenium;
25
26 import static junit.framework.Assert.fail;
27 import static org.junit.Assert.assertTrue;
28
29
30
31
32
33 public abstract class UpgradedSeleniumITBase {
34 private Selenium selenium;
35 protected WebDriver driver;
36
37 protected String getBaseUrlString() {
38 return ITUtil.getBaseUrlString();
39 }
40
41
42
43
44
45
46 public abstract String getTestUrl();
47
48
49
50
51
52 public String getUserName() {
53 return "admin";
54 }
55
56 @Before
57 public void setUp() throws Exception {
58 driver = ITUtil.getWebDriver();
59 if (!getTestUrl().startsWith("/")) {
60 fail("getTestUrl does not start with /");
61 }
62 selenium = new WebDriverBackedSelenium(driver, ITUtil.getBaseUrlString() + getTestUrl());
63
64
65 selenium.open(ITUtil.getBaseUrlString() + getTestUrl());
66 ITUtil.loginSe(selenium, getUserName());
67 }
68
69 protected void assertDocFinal(String docId) {
70 ITUtil.assertDocFinal(selenium, docId);
71 }
72
73 protected void assertElementPresent(String locator) {
74 assertTrue(isElementPresent(locator));
75 }
76
77 protected void assertTextPresent(String text) {
78 assertTextPresent("", text);
79 }
80
81 protected void assertTextPresent(String message, String text) {
82 assertTrue(text + " text not present " + message, selenium.isTextPresent(text));
83 }
84
85 protected void blanketApproveTest() throws InterruptedException {
86 ITUtil.blanketApprove(selenium);
87 }
88
89 protected void close() {
90 selenium.close();
91 }
92
93 protected void check(String locator) {
94 selenium.check(locator);
95 }
96
97 protected void checkErrorMessageItem(String message) {
98 ITUtil.checkErrorMessageItem(selenium, message);
99 }
100
101 protected void checkForIncidentReport(String locator) {
102 checkForIncidentReport(locator, "");
103 }
104
105 protected void checkForIncidentReport(String locator, String message) {
106 ITUtil.checkForIncidentReport(selenium, message);
107 }
108
109 protected void chooseCancelOnNextConfirmation() {
110 selenium.chooseCancelOnNextConfirmation();
111 }
112
113 protected void colapseExpand(String clickLocator, String visibleLocator) throws InterruptedException {
114 waitAndClick(clickLocator);
115 waitNotVisible(visibleLocator);
116
117 waitAndClick(clickLocator);
118 waitIsVisible(visibleLocator);
119 }
120
121 protected void expandColapse(String clickLocator, String visibleLocator) throws InterruptedException {
122 waitAndClick(clickLocator);
123 waitIsVisible(visibleLocator);
124
125 waitAndClick(clickLocator);
126 waitNotVisible(visibleLocator);
127 }
128
129 protected void fireEvent(String locator, String event) {
130 selenium.fireEvent(locator, event);
131 }
132
133 protected void focus(String locator) {
134 selenium.focus(locator);
135 }
136
137 protected void focusAndType(String fieldLocator, String typeText) {
138 selenium.focus(fieldLocator);
139 selenium.type(fieldLocator, typeText);
140 }
141
142 protected String[] getAllWindowTitles() {
143 return selenium.getAllWindowTitles();
144 }
145
146 protected String getAttribute(String attributeLocator) {
147 return selenium.getAttribute(attributeLocator);
148 }
149
150 protected String getConfirmation() {
151 return selenium.getConfirmation();
152 }
153
154 protected Number getCssCount(String cssCountRows) {
155 return selenium.getCssCount(cssCountRows);
156 }
157
158 protected String getSelectedLabel(String locator) {
159 return selenium.getSelectedLabel(locator);
160 }
161
162 protected String[] getSelectOptions(String locator) {
163 return selenium.getSelectOptions(locator);
164 }
165
166 protected String getEval(String script) {
167 return selenium.getEval(script);
168 }
169
170 protected String getLocation() {
171 return selenium.getLocation();
172 }
173
174 protected String getText(String locator) {
175 return selenium.getText(locator);
176 }
177
178 protected String getTitle() {
179 return selenium.getTitle();
180 }
181
182 protected String getValue(String locator) {
183 return selenium.getValue(locator);
184 }
185
186 protected boolean isElementPresent(String locator) {
187 return selenium.isElementPresent(locator);
188 }
189
190 protected boolean isTextPresent(String locator) {
191 return selenium.isTextPresent(locator);
192 }
193
194 protected boolean isVisible(String locator) {
195 return selenium.isVisible(locator);
196 }
197
198 protected void keyDown(String locator, String key) {
199 selenium.keyDown(locator, key);
200 }
201
202 protected void keyPress(String locator, String key) {
203 selenium.keyPress(locator, key);
204 }
205
206 protected void keyUp(String locator, String key) {
207 selenium.keyUp(locator, key);
208 }
209
210 protected void mouseOver(String locator) {
211 selenium.mouseOver(locator);
212 }
213
214 protected void mouseOut(String locator) {
215 selenium.mouseOut(locator);
216 }
217
218 protected void open(String url) {
219 selenium.open(url);
220 }
221
222 protected void removeAllSelections(String locator) {
223 selenium.removeAllSelections(locator);
224 }
225
226 protected void select(String locator, String select) {
227 selenium.select(locator, select);
228 }
229
230 protected void selectFrame(String frameName) {
231 try {
232 selenium.selectFrame(frameName);
233 } catch (NoSuchFrameException nsfe) {
234
235 }
236 }
237
238 protected void setSpeed(String speed) {
239 selenium.setSpeed(speed);
240 }
241
242 protected void selectWindow(String windowName) {
243 selenium.selectWindow(windowName);
244 }
245
246 protected void uncheck(String locator) {
247 selenium.uncheck(locator);
248 }
249
250 protected void waitAndClick(String locator) throws InterruptedException {
251 waitAndClick(locator, "");
252 }
253
254 protected void waitAndClick(String locator, String message) throws InterruptedException {
255 ITUtil.waitAndClick(selenium, locator, message);
256 }
257
258 protected String waitForDocId() throws InterruptedException {
259 ITUtil.waitForElement(selenium, AdminMenuITBase.DOC_ID_LOCATOR);
260 return selenium.getText(AdminMenuITBase.DOC_ID_LOCATOR);
261 }
262
263 protected void waitAndType(String elementLocator, String text) throws InterruptedException {
264 waitAndType(elementLocator, text, "");
265 }
266
267 protected void waitAndType(String elementLocator, String text, String message) throws InterruptedException {
268 ITUtil.waitAndType(selenium, elementLocator, text, message);
269 }
270
271 protected void waitNotVisible(String visibleLocator) throws InterruptedException {
272 for (int second = 0;; second++) {
273 if (second >= 15) {
274 Assert.fail("timeout");
275 }
276
277 if (!isVisible(visibleLocator)) {
278 break;
279 }
280
281 Thread.sleep(1000);
282 }
283 }
284
285 protected void waitIsVisible(String visibleLocator) throws InterruptedException {
286 for (int second = 0;; second++) {
287 if (second >= 15) {
288 Assert.fail("timeout");
289 }
290 if (isVisible(visibleLocator)) {
291 break;
292 }
293 Thread.sleep(1000);
294 }
295 }
296
297 protected void waitForElementPresent(String locator) throws InterruptedException {
298 waitForElementPresent(locator, "");
299 }
300
301
302 protected void waitForElementPresent(String locator, String message) throws InterruptedException {
303 ITUtil.waitForElement(selenium, locator, message);
304 }
305
306 protected void waitForElementVisible(String locator, String message) throws InterruptedException {
307 ITUtil.waitForElementVisible(selenium, locator, message);
308 }
309
310 protected void waitForPageToLoad() {
311 waitForPageToLoad(ITUtil.DEFAULT_WAIT_FOR_PAGE_TO_LOAD_TIMEOUT);
312 }
313
314 protected void waitForPageToLoad50000() {
315 waitForPageToLoad("50000");
316 }
317
318 protected void waitForPageToLoad(String number) {
319 selenium.waitForPageToLoad(number);
320 }
321
322 protected void waitForTitleToEqualKualiPortalIndex() throws InterruptedException {
323 waitForTitleToEqualKualiPortalIndex("");
324 }
325
326 protected void waitForTitleToEqualKualiPortalIndex(String message) throws InterruptedException {
327 ITUtil.waitForTitleToEqual(selenium, ITUtil.KUALI_PORTAL_TITLE, message);
328 }
329
330 protected void windowFocus() {
331 selenium.windowFocus();
332 }
333
334
335
336
337
338
339 @After
340 public void tearDown() throws Exception {
341 if (ITUtil.dontTearDownPropertyNotSet()) {
342 selenium.stop();
343 driver.quit();
344 }
345 }
346 }