packagepl.labno.bernard.htmlunified;importcom.gargoylesoftware.htmlunit.BrowserVersion;importcom.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;importcom.gargoylesoftware.htmlunit.WebClient;importcom.gargoylesoftware.htmlunit.html.HtmlElement;importcom.gargoylesoftware.htmlunit.html.HtmlInput;importcom.gargoylesoftware.htmlunit.html.HtmlPage;importcom.gargoylesoftware.htmlunit.html.HtmlSpan;importcom.gargoylesoftware.htmlunit.html.HtmlTableCell;importorg.junit.Assert;importorg.junit.Test;importjava.io.IOException;importjava.util.ArrayList;importjava.util.List;importjava.util.Map;publicclassScheduleTest{// @TestpublicvoidaccessEventTitles()throwsIOException{WebClientclient=newWebClient(BrowserVersion.FIREFOX_3_6);//login-----------------------------------HtmlPagepage=(HtmlPage)client.getPage("http://localhost:8080/schoolmanager/view/class/current.seam?networkId=salsafactory");((HtmlInput)page.getElementById("loginForm:email")).setValueAttribute("s4237@pjwstk.edu.pl");((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);//----------------------------------------finalList<HtmlSpan>titleElements=(List<HtmlSpan>)page.getElementById("results:schedule").getByXPath(".//span[@class='fc-event-title']");List<String>titles=newArrayList<String>(titleElements.size());for(HtmlSpano:titleElements){titles.add(o.asText());}Assert.assertEquals(2,titles.size());}@TestpublicvoidclickSuggestionBox()throwsIOException{WebClientclient=newWebClient(BrowserVersion.FIREFOX_3_6);client.setAjaxController(newNicelyResynchronizingAjaxController());//login-----------------------------------HtmlPagepage=(HtmlPage)client.getPage("http://localhost:8080/schoolmanager/view/class/current.seam?networkId=salsafactory");((HtmlInput)page.getElementById("loginForm:email")).setValueAttribute("s4237@pjwstk.edu.pl");((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);//----------------------------------------finalHtmlInputstudentInput=(HtmlInput)page.getElementById("searchClass:student_i");intinitialJobs=client.waitForBackgroundJavaScript(10);studentInput.type('w');studentInput.type('i');Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(),page);// Here the suggestionBox is still hidden// System.out.println(page.asXml());intjobs=WebClientUtils.waitForJSJob(client,0,30000);// Here suggestionBox is visible// System.out.println(page.asXml());System.out.println(page.getElementById("searchClass:sS").asXml());System.out.println("initialJobs:"+initialJobs);System.out.println("jobs:"+jobs);Assert.assertEquals(client.getCurrentWindow().getEnclosedPage(),page);synchronized(page){try{page.wait(1000);}catch(InterruptedExceptione){e.printStackTrace();//To change body of catch statement use File | Settings | File Templates.}}Map<String,HtmlTableCell>suggestions=WebClientUtils.getSuggestions(page.getElementById("searchClass:sS"),0);Assert.assertEquals(1,suggestions.size());System.out.println(suggestions);HtmlTableCellcell=suggestions.get("Willis Bruce");Assert.assertNotNull(cell);initialJobs=client.waitForBackgroundJavaScript(10);System.out.println("initial jobs:"+initialJobs);cell.click();System.out.println("Starting jobs:"+client.waitForBackgroundJavaScriptStartingBefore(3000));System.out.println("Running jobs:"+client.waitForBackgroundJavaScript(10));// studentInput.type('\t');jobs=WebClientUtils.waitForJSJob(client,initialJobs,30000);System.out.println("initialJobs:"+initialJobs);System.out.println("jobs:"+jobs);System.out.println(page.asXml());Assert.assertEquals("Willis Bruce",((HtmlElement)page.getByXPath("//*[@id='searchClass:searchStudent']").get(0)).asText());}}