1
|
package pl.labno.bernard.htmlunified;
|
1
|
package pl.labno.bernard.htmlunified;
|
2
|
|
2
|
|
3
|
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
3
|
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
4
|
-import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
|
|
|
5
|
import com.gargoylesoftware.htmlunit.WebClient;
|
4
|
import com.gargoylesoftware.htmlunit.WebClient;
|
6
|
import com.gargoylesoftware.htmlunit.html.HtmlElement;
|
5
|
import com.gargoylesoftware.htmlunit.html.HtmlElement;
|
7
|
import com.gargoylesoftware.htmlunit.html.HtmlInput;
|
6
|
import com.gargoylesoftware.htmlunit.html.HtmlInput;
|
|
@@ -16,83 +15,137 @@ import java.util.ArrayList; |
|
@@ -16,83 +15,137 @@ import java.util.ArrayList; |
16
|
import java.util.List;
|
15
|
import java.util.List;
|
17
|
import java.util.Map;
|
16
|
import java.util.Map;
|
18
|
|
17
|
|
|
|
18
|
+/**
|
|
|
19
|
+ * NicelyResynchronizingAjaxController is EVIL! Don't use it!
|
|
|
20
|
+ */
|
19
|
public class ScheduleTest {
|
21
|
public class ScheduleTest {
|
20
|
|
22
|
|
21
|
- // @Test
|
23
|
+ @Test
|
22
|
public void accessEventTitles() throws IOException {
|
24
|
public void accessEventTitles() throws IOException {
|
23
|
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
|
25
|
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
|
24
|
- //login-----------------------------------
|
|
|
25
|
- HtmlPage page = (HtmlPage) client.getPage("http://localhost:8080/schoolmanager/view/class/current.seam?networkId=salsafactory");
|
|
|
26
|
- ((HtmlInput) page.getElementById("loginForm:email")).setValueAttribute("s4237@pjwstk.edu.pl");
|
|
|
27
|
- ((HtmlInput) page.getElementById("loginForm:password")).setValueAttribute("aaaaa");
|
|
|
28
|
- HtmlPage oldPage = page;
|
|
|
29
|
- page = page.getElementById("loginForm:submit").click();
|
|
|
30
|
-// This assert would fail (when page redidrects than you need to obtain new page)
|
|
|
31
|
-// Assert.assertEquals(page,oldPage);
|
|
|
32
|
- Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
|
|
33
|
- //----------------------------------------
|
|
|
34
|
-
|
26
|
+ HtmlPage page = login(client);
|
|
|
27
|
+ @SuppressWarnings("unchecked")
|
35
|
final List<HtmlSpan> titleElements = (List<HtmlSpan>) page.getElementById("results:schedule").getByXPath(".//span[@class='fc-event-title']");
|
28
|
final List<HtmlSpan> titleElements = (List<HtmlSpan>) page.getElementById("results:schedule").getByXPath(".//span[@class='fc-event-title']");
|
36
|
List<String> titles = new ArrayList<String>(titleElements.size());
|
29
|
List<String> titles = new ArrayList<String>(titleElements.size());
|
37
|
for (HtmlSpan o : titleElements) {
|
30
|
for (HtmlSpan o : titleElements) {
|
38
|
titles.add(o.asText());
|
31
|
titles.add(o.asText());
|
39
|
}
|
32
|
}
|
40
|
- Assert.assertEquals(2, titles.size());
|
33
|
+ Assert.assertEquals(4, titles.size());
|
41
|
}
|
34
|
}
|
42
|
|
35
|
|
43
|
@Test
|
36
|
@Test
|
44
|
- public void clickSuggestionBox() throws IOException {
|
37
|
+ public void clickStudentSuggestionBox() throws IOException {
|
45
|
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
|
38
|
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
|
46
|
- client.setAjaxController(new NicelyResynchronizingAjaxController());
|
|
|
47
|
- //login-----------------------------------
|
|
|
48
|
- HtmlPage page = (HtmlPage) client.getPage("http://localhost:8080/schoolmanager/view/class/current.seam?networkId=salsafactory");
|
|
|
49
|
- ((HtmlInput) page.getElementById("loginForm:email")).setValueAttribute("s4237@pjwstk.edu.pl");
|
|
|
50
|
- ((HtmlInput) page.getElementById("loginForm:password")).setValueAttribute("aaaaa");
|
|
|
51
|
- HtmlPage oldPage = page;
|
|
|
52
|
- page = page.getElementById("loginForm:submit").click();
|
|
|
53
|
-// This assert would fail (when page redidrects than you need to obtain new page)
|
|
|
54
|
-// Assert.assertEquals(page,oldPage);
|
|
|
55
|
- Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
|
|
56
|
- //----------------------------------------
|
|
|
57
|
- final HtmlInput studentInput = (HtmlInput) page.getElementById("searchClass:student_i");
|
|
|
58
|
- int initialJobs = client.waitForBackgroundJavaScript(10);
|
|
|
59
|
-
|
39
|
+ HtmlPage page = login(client);
|
|
|
40
|
+ page.addDomChangeListener(new DomChangeLogger());
|
|
|
41
|
+ page.getElementById("searchClass:sS").addHtmlAttributeChangeListener(new HtmlAttributeChangeLogger());
|
|
|
42
|
+ HtmlInput studentInput = (HtmlInput) page.getElementById("searchClass:student_i");
|
60
|
studentInput.type('w');
|
43
|
studentInput.type('w');
|
61
|
studentInput.type('i');
|
44
|
studentInput.type('i');
|
62
|
Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
45
|
Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
63
|
// Here the suggestionBox is still hidden
|
46
|
// Here the suggestionBox is still hidden
|
64
|
-// System.out.println(page.asXml());
|
|
|
65
|
-
|
|
|
66
|
- int jobs = WebClientUtils.waitForJSJob(client, 0, 30000);
|
47
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
67
|
// Here suggestionBox is visible
|
48
|
// Here suggestionBox is visible
|
68
|
-// System.out.println(page.asXml());
|
|
|
69
|
- System.out.println(page.getElementById("searchClass:sS").asXml());
|
|
|
70
|
- System.out.println("initialJobs:" + initialJobs);
|
|
|
71
|
- System.out.println("jobs:" + jobs);
|
|
|
72
|
Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
49
|
Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
73
|
- synchronized (page) {
|
|
|
74
|
- try {
|
|
|
75
|
- page.wait(1000);
|
|
|
76
|
- } catch (InterruptedException e) {
|
|
|
77
|
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
|
|
78
|
- }
|
|
|
79
|
- }
|
|
|
80
|
Map<String, HtmlTableCell> suggestions = WebClientUtils.getSuggestions(page.getElementById("searchClass:sS"), 0);
|
50
|
Map<String, HtmlTableCell> suggestions = WebClientUtils.getSuggestions(page.getElementById("searchClass:sS"), 0);
|
81
|
Assert.assertEquals(1, suggestions.size());
|
51
|
Assert.assertEquals(1, suggestions.size());
|
82
|
System.out.println(suggestions);
|
52
|
System.out.println(suggestions);
|
83
|
HtmlTableCell cell = suggestions.get("Willis Bruce");
|
53
|
HtmlTableCell cell = suggestions.get("Willis Bruce");
|
84
|
Assert.assertNotNull(cell);
|
54
|
Assert.assertNotNull(cell);
|
85
|
- initialJobs = client.waitForBackgroundJavaScript(10);
|
|
|
86
|
- System.out.println("initial jobs:"+initialJobs);
|
|
|
87
|
cell.click();
|
55
|
cell.click();
|
88
|
- System.out.println("Starting jobs:"+client.waitForBackgroundJavaScriptStartingBefore(3000));
|
|
|
89
|
- System.out.println("Running jobs:"+client.waitForBackgroundJavaScript(10));
|
|
|
90
|
-// studentInput.type('\t');
|
|
|
91
|
- jobs = WebClientUtils.waitForJSJob(client,initialJobs, 30000);
|
|
|
92
|
- System.out.println("initialJobs:" + initialJobs);
|
|
|
93
|
- System.out.println("jobs:" + jobs);
|
|
|
94
|
- System.out.println(page.asXml());
|
|
|
95
|
- Assert.assertEquals("Willis Bruce",((HtmlElement)page.getByXPath("//*[@id='searchClass:searchStudent']").get(0)).asText());
|
56
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
57
|
+ Assert.assertEquals("Willis Bruce", ((HtmlElement) page.getByXPath("//*[@id='searchClass:searchStudent']").get(0)).asText());
|
|
|
58
|
+ System.out.println("Success!");
|
|
|
59
|
+
|
|
|
60
|
+
|
|
|
61
|
+// page = (HtmlPage) client.getPage("http://localhost:8080/schoolmanager/view/class/current.seam?networkId=salsafactory");
|
|
|
62
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
63
|
+ Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
|
|
64
|
+ studentInput = (HtmlInput) page.getElementById("searchClass:student_i");
|
|
|
65
|
+ studentInput.setValueAttribute("");
|
|
|
66
|
+ studentInput.type('l');
|
|
|
67
|
+ studentInput.type('i');
|
|
|
68
|
+ Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
|
|
69
|
+// WebClientUtils.forceWait(2000);
|
|
|
70
|
+// Here the suggestionBox is still hidden
|
|
|
71
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
72
|
+// Here suggestionBox is visible
|
|
|
73
|
+ Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
|
|
74
|
+ suggestions = WebClientUtils.getSuggestions(page.getElementById("searchClass:sS"), 0);
|
|
|
75
|
+ Assert.assertEquals(1, suggestions.size());
|
|
|
76
|
+ System.out.println(suggestions);
|
|
|
77
|
+ cell = suggestions.get("Linda Bogusław");
|
|
|
78
|
+ Assert.assertNotNull(cell);
|
|
|
79
|
+ cell.click();
|
|
|
80
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
81
|
+ Assert.assertEquals("Linda Bogusław", ((HtmlElement) page.getByXPath("//*[@id='searchClass:searchStudent']").get(0)).asText());
|
|
|
82
|
+ System.out.println("Success2!");
|
|
|
83
|
+ }
|
|
|
84
|
+
|
|
|
85
|
+ @Test
|
|
|
86
|
+ public void switchBetwenScheduleAndTableMode() throws IOException {
|
|
|
87
|
+ WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
|
|
|
88
|
+ HtmlPage page = login(client);
|
|
|
89
|
+ page.getElementById("j_id2118:j_id2119:0").click();
|
|
|
90
|
+ page.getElementById("j_id2118:j_id2119:0").blur();
|
|
|
91
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
92
|
+// System.out.println(page.getElementById("results").asXml());
|
|
|
93
|
+ Assert.assertNotNull(page.getElementById("results:table"));
|
|
|
94
|
+ page.getElementById("j_id2118:j_id2119:1").click();
|
|
|
95
|
+ page.getElementById("j_id2118:j_id2119:1").blur();
|
|
|
96
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
97
|
+// System.out.println(page.getElementById("results").asXml());
|
|
|
98
|
+ Assert.assertNotNull(page.getElementById("results:schedule"));
|
|
|
99
|
+ page.getElementById("j_id2118:j_id2119:0").click();
|
|
|
100
|
+ page.getElementById("j_id2118:j_id2119:0").blur();
|
|
|
101
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
102
|
+// System.out.println(page.getElementById("results").asXml());
|
|
|
103
|
+ Assert.assertNotNull(page.getElementById("results:table"));
|
|
|
104
|
+ }
|
|
|
105
|
+
|
|
|
106
|
+ @Test
|
|
|
107
|
+ public void selectStudentSuggestionByTab() throws IOException {
|
|
|
108
|
+ final WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
|
|
|
109
|
+ final RequestResponseLogger requestResponseLogger = new RequestResponseLogger(client);
|
|
|
110
|
+ requestResponseLogger.off();
|
|
|
111
|
+ HtmlPage page = login(client);
|
|
|
112
|
+ final HtmlInput studentInput = (HtmlInput) page.getElementById("searchClass:student_i");
|
|
|
113
|
+ studentInput.type('w');
|
|
|
114
|
+ studentInput.type('i');
|
|
|
115
|
+ Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
|
|
116
|
+// Here the suggestionBox is still hidden
|
|
|
117
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
118
|
+// Here suggestionBox is visible
|
|
|
119
|
+ Map<String, HtmlTableCell> suggestions = WebClientUtils.getSuggestions(page.getElementById("searchClass:sS"), 0);
|
|
|
120
|
+ Assert.assertEquals(1, suggestions.size());
|
|
|
121
|
+// System.out.println(suggestions);
|
|
|
122
|
+ HtmlTableCell cell = suggestions.get("Willis Bruce");
|
|
|
123
|
+ Assert.assertNotNull(cell);
|
|
|
124
|
+ studentInput.type('\t');
|
|
|
125
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
126
|
+ Assert.assertEquals("Willis Bruce", page.getElementById("searchClass:searchStudent").asText());
|
|
|
127
|
+
|
|
|
128
|
+// requestResponseLogger.on();
|
|
|
129
|
+// client.setAlertHandler(new AlertLogger());
|
|
|
130
|
+// page.addDomChangeListener(new DomChangeLogger());
|
|
|
131
|
+ final HtmlElement element = page.getElementById("searchClass:searchStudent").getElementsByTagName("img").get(0);
|
|
|
132
|
+ element.click();
|
|
|
133
|
+ WebClientUtils.waitForJSJob(client, 0, 30000);
|
|
|
134
|
+ Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
|
|
135
|
+ Assert.assertEquals("", page.getElementById("searchClass:searchStudent").asText());
|
|
|
136
|
+
|
|
|
137
|
+ }
|
|
|
138
|
+
|
|
|
139
|
+ private HtmlPage login(WebClient client) throws IOException {
|
|
|
140
|
+ HtmlPage page = (HtmlPage) client.getPage("http://localhost:8080/schoolmanager/view/class/current.seam?networkId=salsafactory");
|
|
|
141
|
+ ((HtmlInput) page.getElementById("loginForm:email")).setValueAttribute("s4237@pjwstk.edu.pl");
|
|
|
142
|
+ ((HtmlInput) page.getElementById("loginForm:password")).setValueAttribute("aaaaa");
|
|
|
143
|
+ HtmlPage oldPage = page;
|
|
|
144
|
+ page = page.getElementById("loginForm:submit").click();
|
|
|
145
|
+// This assert would fail (when page redidrects than you need to obtain new page)
|
|
|
146
|
+// Assert.assertEquals(page,oldPage);
|
|
|
147
|
+ Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
|
|
|
148
|
+ return page;
|
96
|
}
|
149
|
}
|
97
|
|
150
|
|
98
|
} |
151
|
} |