1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.demo.uif.library.clientresponsiveness;
17
18 import org.junit.Ignore;
19 import org.junit.Test;
20
21 import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
22 import org.kuali.rice.testtools.selenium.WebDriverUtils;
23 import org.openqa.selenium.By;
24 import org.openqa.selenium.Keys;
25 import org.openqa.selenium.WebElement;
26
27
28
29
30 public class LibraryClientResponsivenessAjaxFieldQueryAft extends WebDriverLegacyITBase {
31
32
33
34
35 public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-AjaxFieldQueryView";
36
37 @Override
38 protected String getBookmarkUrl() {
39 return BOOKMARK_URL;
40 }
41
42 @Override
43 protected void navigate() throws Exception {
44 waitAndClickLibraryLink();
45 waitAndClickByLinkText("Client Responsiveness");
46 waitAndClickByLinkText("AJAX Field Query");
47 }
48
49 protected void testClientResponsivenessAjaxFieldQuery() throws Exception {
50 waitAndClickByLinkText("Ajax Field Query");
51 waitForElementPresentByXpath("//input[@name='inputField3' and @value='a1']");
52 clearTypeAndFocus("inputField3", "a1");
53 checkIfFocusSuccessful("inputField3", "a1", "Travel Account 1");
54 assertTextPresent(new String[] {"Travel Account 1", "fred"});
55 }
56
57 protected void testClientResponsivenessAjaxFieldQueryCustomMethod() throws Exception {
58 waitAndClickByLinkText("Ajax Field Query Custom Method");
59 waitForElementPresentByXpath("//input[@name='inputField6' and @value='a2']");
60 clearTypeAndFocus("inputField6", "a2");
61 checkIfFocusSuccessful("inputField6", "a2", "Travel Account 2");
62 assertTextPresent(new String[] {"Travel Account 2", "fran"});
63 }
64
65 protected void testClientResponsivenessAjaxFieldQueryCustomMethodAndService() throws Exception {
66 waitAndClickByLinkText("Ajax Field Query Custom Method and Service");
67 waitForElementPresentByXpath("//input[@name='inputField9' and @value='a3']");
68 clearTypeAndFocus("inputField9", "a3");
69 checkIfFocusSuccessful("inputField9", "a3", "Travel Account 3");
70 assertTextPresent(new String[] {"Travel Account 3", "frank"});
71 }
72
73
74
75
76
77
78
79
80
81 private void clearTypeAndFocus(String fieldName, String fieldValue) throws InterruptedException {
82 clearTextByName(fieldName);
83 WebElement element = WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.name(
84 fieldName), this.getClass().toString());
85 element.sendKeys("", fieldValue);
86 fireEvent(fieldName, "focus");
87 fireEvent(fieldName, "blur");
88 assertTextPresent(fieldValue);
89 }
90
91
92
93
94
95
96
97
98
99
100
101 private void checkIfFocusSuccessful(String fieldName, String fieldValue, String expectedMessage)
102 throws InterruptedException {
103 for (int i = 0; i < 5; i++) {
104 Thread.sleep(3000);
105 if (isTextPresent(expectedMessage)) {
106 break;
107 } else {
108 jGrowl("Focus failed - Focusing back on the test window before trying to enter text again.");
109 driver.switchTo().window(driver.getWindowHandle());
110 clearTypeAndFocus(fieldName, fieldValue);
111 }
112 }
113 }
114
115 @Test
116 public void testClientResponsivenessAjaxFieldQueryBookmark() throws Exception {
117 testClientResponsivenessAjaxFieldQuery();
118 testClientResponsivenessAjaxFieldQueryCustomMethod();
119 passed();
120 }
121
122 @Test
123 public void testClientResponsivenessAjaxFieldQueryNav() throws Exception {
124 testClientResponsivenessAjaxFieldQuery();
125 testClientResponsivenessAjaxFieldQueryCustomMethod();
126 passed();
127 }
128
129 @Test
130 @Ignore
131 public void testClientResponsivenessAjaxFieldQueryCustomMethodAndServiceBookmark() throws Exception {
132 testClientResponsivenessAjaxFieldQueryCustomMethodAndService();
133 passed();
134 }
135
136 @Test
137 @Ignore
138 public void testClientResponsivenessAjaxFieldQueryCustomMethodAndServiceNav() throws Exception {
139 testClientResponsivenessAjaxFieldQueryCustomMethodAndService();
140 passed();
141 }
142 }