packagepl.labno.bernard.htmlunified;importcom.gargoylesoftware.htmlunit.BrowserVersion;importcom.gargoylesoftware.htmlunit.WebClient;importcom.gargoylesoftware.htmlunit.html.HtmlElement;importcom.gargoylesoftware.htmlunit.html.HtmlInput;importcom.gargoylesoftware.htmlunit.html.HtmlPage;importcom.gargoylesoftware.htmlunit.html.HtmlSpan;importorg.junit.Assert;importorg.junit.Test;importjava.io.IOException;importjava.util.List;publicclassClassDetailsTest{@TestpublicvoidopenDetailsModalPanel()throwsIOException{WebClientclient=newWebClient(BrowserVersion.FIREFOX_3_6);HtmlPagepage=login(client);@SuppressWarnings("unchecked")finalList<HtmlSpan>titleElements=(List<HtmlSpan>)page.getElementById("results:schedule").getByXPath(".//span[@class='fc-event-title']");Assert.assertNotSame(0,titleElements.size());newRequestResponseLogger(client);page.addDomChangeListener(newDomChangeLogger());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"));}@TestpublicvoidcloseDetailsModalPanel()throwsIOException{WebClientclient=newWebClient(BrowserVersion.FIREFOX_3_6);HtmlPagepage=login(client);@SuppressWarnings("unchecked")finalList<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"));}@TestpublicvoidremoveClass()throwsIOException{WebClientclient=newWebClient(BrowserVersion.FIREFOX_2);finalRequestResponseLoggerrequestResponseLogger=newRequestResponseLogger(client);requestResponseLogger.off();HtmlPagepage=login(client);@SuppressWarnings("unchecked")finalList<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(newAlertLogger());finalDomChangeLoggerdomChangeLogger=newDomChangeLogger();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());}privateHtmlPagelogin(WebClientclient)throwsIOException{HtmlPagepage=(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");HtmlPageoldPage=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);returnpage;}}