ClassDetailsTest.java
5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package pl.labno.bernard.htmlunified;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSpan;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
public class ClassDetailsTest {
@Test
public void openDetailsModalPanel() throws IOException {
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
HtmlPage page = login(client);
@SuppressWarnings("unchecked")
final List<HtmlSpan> titleElements = (List<HtmlSpan>) page.getElementById("results:schedule").getByXPath(".//span[@class='fc-event-title']");
Assert.assertNotSame(0, titleElements.size());
new RequestResponseLogger(client);
page.addDomChangeListener(new DomChangeLogger());
WebClientUtils.waitForJSJob("initial javascript to finish", client, 0, 30000);
System.out.println("item:" + titleElements.get(0).asText());
((HtmlElement) titleElements.get(0).getParentNode()).mouseOver();
((HtmlElement) titleElements.get(0).getParentNode()).click();
WebClientUtils.waitForJSJob("classDetailsModalPanel shown after schedule event clicked", client, 0, 30000);
Assert.assertNotNull(page.getElementById("classDetailsModalPanelContainer"));
}
@Test
public void closeDetailsModalPanel() throws IOException {
WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
HtmlPage page = login(client);
@SuppressWarnings("unchecked")
final List<HtmlSpan> titleElements = (List<HtmlSpan>) page.getElementById("results:schedule").getByXPath(".//span[@class='fc-event-title']");
Assert.assertNotSame(0, titleElements.size());
// new RequestResponseLogger(client);
// page.addDomChangeListener(new DomChangeLogger());
WebClientUtils.waitForJSJob("initial javascript to finish", client, 0, 30000);
System.out.println("item:" + titleElements.get(0).asText());
((HtmlElement) titleElements.get(0).getParentNode()).mouseOver();
((HtmlElement) titleElements.get(0).getParentNode()).click();
WebClientUtils.waitForJSJob("classDetailsModalPanel shown after schedule event clicked", client, 0, 30000);
Assert.assertNotNull(page.getElementById("classDetailsModalPanelContainer"));
((HtmlElement) page.getElementById("classDetailsModalPanelContainer").getByXPath("//*[contains(@src,'close.png')]").get(0)).click();
WebClientUtils.waitForJSJob("classDetailsModalPanel hidden after cancel button", client, 0, 30000);
Assert.assertNull(page.getElementById("classDetailsModalPanelContainer"));
}
@Test
public void removeClass() throws IOException {
WebClient client = new WebClient(BrowserVersion.FIREFOX_2);
final RequestResponseLogger requestResponseLogger = new RequestResponseLogger(client);
requestResponseLogger.off();
HtmlPage page = login(client);
@SuppressWarnings("unchecked")
final List<HtmlSpan> titleElements = (List<HtmlSpan>) page.getElementById("results:schedule").getByXPath(".//span[@class='fc-event-title']");
Assert.assertEquals(6, titleElements.size());
Assert.assertNotSame(0, titleElements.size());
WebClientUtils.waitForJSJob("initial javascript to finish", client, 0, 30000);
client.setAlertHandler(new AlertLogger());
final DomChangeLogger domChangeLogger = new DomChangeLogger();
domChangeLogger.showDetails("results:j_id2158");
// page.addDomChangeListener(domChangeLogger);
// page.addHtmlAttsributeChangeListener(new HtmlAttributeChangeLogger());
// requestResponseLogger.on();
((HtmlElement) titleElements.get(0).getParentNode()).mouseOver();
((HtmlElement) titleElements.get(0).getParentNode()).click();
WebClientUtils.waitForJSJob("classDetailsModalPanel shown after schedule event clicked", client, 0, 30000);
WebClientUtils.executeAjaxReRenderedScripts(page);
Assert.assertNotNull(page.getElementById("classDetailsModalPanelContainer"));
((HtmlElement) page.getElementById("classDetailsModalPanelContainer").getByXPath("//*[contains(@src,'remove.png')]").get(0)).click();
WebClientUtils.waitForJSJob("classDetailsModalPanel hidden after remove button", client, 0, 30000);
WebClientUtils.executeAjaxReRenderedScripts(page);
WebClientUtils.waitForJSJob("schedule refresh", client, 0, 30000);
Assert.assertNull(page.getElementById("classDetailsModalPanelContainer"));
Assert.assertEquals(5, page.getElementById("results:schedule").getByXPath(".//span[@class='fc-event-title']").size());
}
private HtmlPage login(WebClient client) throws IOException {
HtmlPage page = (HtmlPage) client.getPage("http://localhost:8080/schoolmanager/view/class/current.seam?networkId=salsafactory");
((HtmlInput) page.getElementById("loginForm:email")).setValueAttribute("it.crowd.test@gmail.com");
((HtmlInput) page.getElementById("loginForm:password")).setValueAttribute("aaaaa");
HtmlPage oldPage = page;
page = page.getElementById("loginForm:submit").click();
// This assert would fail (when page redidrects than you need to obtain new page)
// Assert.assertEquals(page,oldPage);
Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(), page);
return page;
}
}