@Test @Ignore public void test3() throws Exception { System.out.println("-------------------------------"); WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setCssEnabled(false); webClient.getOptions().setJavaScriptEnabled(false); HtmlPage page = webClient.getPage("http://www.zjnu.edu.cn/news/common/article_show.aspx?article_id=19285"); System.out.println("---------------标题----------------"); HtmlSpan span1 = (HtmlSpan) page.getElementById("mytitle"); System.out.println(span1.asText()); System.out.println("-------------------------------"); System.out.println("---------------正文----------------"); HtmlSpan span2 = (HtmlSpan) page.getElementById("mycontent"); System.out.println(span2.asText()); System.out.println("-------------------------------"); System.out.println("---------------图片----------------"); DomNodeList<HtmlElement> elements = span2.getElementsByTagName("img"); for (HtmlElement element : elements) { System.out.println(element.getAttribute("src")); } // log.debug("{}", elements); System.out.println("-------------------------------"); webClient.close(); System.out.println("-------------------------------"); }
/** @throws Exception if the test fails */ @Test @Alerts(FF = "[object SVGFEFuncBElement]", IE = "[object HTMLGenericElement]") public void simpleScriptable() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + " function test() {\n" + " alert(document.getElementById('myId'));\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + " <svg xmlns='http://www.w3.org/2000/svg' version='1.1'>\n" + " <feFuncB id='myId'/>\n" + " </svg>\n" + "</body></html>"; final WebDriver driver = loadPageWithAlerts2(html); if (driver instanceof HtmlUnitDriver) { final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage(); if ("[object SVGFEFuncBElement]".equals(getExpectedAlerts()[0])) { assertTrue(SvgFeFuncBLight.class.isInstance(page.getElementById("myId"))); } else { assertTrue(HtmlUnknownElement.class.isInstance(page.getElementById("myId"))); } } }
@Test public void testSetValueListLayout() throws Exception { HtmlPage page = environment.getPage("/autocompleteListLayoutTest.jsf"); HtmlElement autocompleteList = page.getElementById("form:myAutocompleteList"); Assert.assertNotNull(autocompleteList); List<?> countryList = autocompleteList.getByXPath("div/div/div/ul/li"); Assert.assertEquals(30, countryList.size()); HtmlInput input = (HtmlInput) page.getElementById("form:myAutocompleteInput"); Assert.assertNotNull(input); input.type("be"); for (int i = 0; i < 20; i++) { synchronized (page) { autocompleteList = page.getElementById("form:myAutocompleteList"); Assert.assertNotNull(autocompleteList); countryList = autocompleteList.getByXPath("div/div/div/ul/li"); if (countryList.size() == 5) { break; } else { page.wait(500); } } } Assert.assertEquals(5, countryList.size()); }
/** * This test verifies that an attribute named 'readonly' can be successfully updated from a * partial response (over Ajax). */ @Test public void testUpdateAttributeNamedReadonly() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/attributeNameIsReadonly.xhtml"); HtmlTextInput input = (HtmlTextInput) page.getElementById("form1:foo"); assertTrue(input.isReadOnly() == false); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form1:button"); page = button.click(); webClient.waitForBackgroundJavaScript(60000); input = (HtmlTextInput) page.getElementById("form1:foo"); assertTrue(input.isReadOnly() == true); }
@JsfTest(value = JSF_2_2_0) @Test public void testSessionLogging() throws Exception { HtmlPage page = webClient.getPage(webUrl); HtmlElement e = (HtmlElement) page.getElementById("initMessage"); long sessionInitTime = Long.valueOf(e.asText()); HtmlSubmitInput invalidateButton = (HtmlSubmitInput) page.getElementById("invalidateSession"); page = invalidateButton.click(); e = (HtmlElement) page.getElementById("destroyMessage"); long sessionDestroyTime = Long.valueOf(e.asText()); assertTrue(sessionInitTime < sessionDestroyTime); }
@JsfTest(value = JSF_2_2_0) @Test public void testViewScopedLogging() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/viewScoped01.xhtml"); HtmlElement e = (HtmlElement) page.getElementById("initMessage"); long flowInitTime = Long.valueOf(e.asText()); HtmlSubmitInput returnButton = (HtmlSubmitInput) page.getElementById("viewScoped02"); page = returnButton.click(); e = (HtmlElement) page.getElementById("destroyMessage"); long flowDestroyTime = Long.valueOf(e.asText()); assertTrue(flowInitTime < flowDestroyTime); }
/** * This test verifies that an attribute named 'checked' can be successfully updated from a partial * response (over Ajax). */ @Test public void testUpdateAttributeNamedChecked() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/attributeNameIsChecked.xhtml"); HtmlCheckBoxInput cbox = (HtmlCheckBoxInput) page.getElementById("form1:foo"); assertTrue(cbox.isChecked() == false); assertTrue(page.asXml().contains("foo")); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form1:button"); page = button.click(); webClient.waitForBackgroundJavaScript(60000); cbox = (HtmlCheckBoxInput) page.getElementById("form1:foo"); assertTrue(cbox.isChecked() == true); }
@JsfTest(value = JSF_2_2_0) @Test public void testFlowLogging() throws Exception { HtmlPage page = webClient.getPage(webUrl); HtmlSubmitInput enterFlow = (HtmlSubmitInput) page.getElementById("enterFlow"); page = enterFlow.click(); HtmlElement e = (HtmlElement) page.getElementById("initMessage"); long flowInitTime = Long.valueOf(e.asText()); HtmlSubmitInput next = (HtmlSubmitInput) page.getElementById("a"); page = next.click(); HtmlSubmitInput returnButton = (HtmlSubmitInput) page.getElementById("return"); page = returnButton.click(); e = (HtmlElement) page.getElementById("destroyMessage"); long flowDestroyTime = Long.valueOf(e.asText()); assertTrue(flowInitTime < flowDestroyTime); }
@Test public void testStable() throws Exception { String inputValue1 = "value=" + '"' + "1" + '"'; String inputValue2 = "value=" + '"' + "2" + '"'; String idText3 = "id=" + '"' + "text3" + '"'; /* * Make sure the three dynamically added input components are in their proper place. */ HtmlPage page = webClient.getPage(webUrl + "faces/stable.xhtml"); assertTrue(page.asXml().indexOf("encodeBegin") < page.asXml().indexOf(inputValue1)); assertTrue(page.asXml().indexOf(inputValue1) < page.asXml().indexOf(inputValue2)); assertTrue(page.asXml().indexOf(inputValue2) < page.asXml().indexOf(idText3)); assertTrue(page.asXml().indexOf("text3") < page.asXml().indexOf("encodeEnd")); /** * After clicking make sure the added component is still in its proper place. Also verify the * validation required error message appears as the third input component has required attribute * set to true. */ HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button"); page = button.click(); assertTrue(page.asXml().contains("text3: Validation Error: Value is required.")); assertTrue(page.asXml().indexOf("encodeBegin") < page.asXml().indexOf(inputValue1)); assertTrue(page.asXml().indexOf(inputValue1) < page.asXml().indexOf(inputValue2)); assertTrue(page.asXml().indexOf(inputValue2) < page.asXml().indexOf(idText3)); assertTrue(page.asXml().indexOf("text3") < page.asXml().indexOf("encodeEnd")); }
@Test(groups = {"notLoggedIn"}) public void testUserFilterWithAjaxDeny() throws Exception { clickOnBasePage("tynamoLoginLink"); loginAction(); clickOnBasePage("contributed"); // now go log out in a different "window" HtmlPage indexPage = webClient.getPage(BASEURI); indexPage.getHtmlElementById("tynamoLogoutLink").click(); // Clicking on this link should make an ajax request, but HTMLUnit doesn't like it and sends a // non-ajax request HtmlElement ajaxLink = (HtmlElement) page.getElementById("ajaxLink"); URL ajaxUrl = new URL(APP_HOST_PORT + ajaxLink.getAttribute("href")); WebRequest ajaxRequest = new WebRequest(ajaxUrl); ajaxRequest.setAdditionalHeader("X-Requested-With", "XMLHttpRequest"); Page jsonLoginResponse = webClient.getPage(ajaxRequest); String ajaxLoginResp = jsonLoginResponse.getWebResponse().getContentAsString(); JSONObject jsonResp = new JSONObject(ajaxLoginResp); String ajaxRedirectUrl = jsonResp.getJSONObject("_tapestry").getString("redirectURL"); assertTrue( ajaxRedirectUrl.startsWith(APP_CONTEXT + "security/login"), "The ajax redirect response '" + ajaxRedirectUrl + "' did not start with '" + APP_CONTEXT + "security/login'"); page = webClient.getPage(APP_HOST_PORT + ajaxRedirectUrl); assertLoginPage(); }
public static boolean inHospital(HtmlPage page) { HtmlElement e = page.getElementById("icon15"); if (e == null) return false; boolean result = e.getAttribute("title").toLowerCase().contains("hospital"); if (result) System.out.println("In hospital."); return result; }
@Test public void testReplaceVDL() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/replacevdl.xhtml"); String text = page.asText(); assertTrue(text.indexOf("buildView") != -1); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button"); page = button.click(); text = page.asText(); assertTrue(text.indexOf("buildView") != -1); button = (HtmlSubmitInput) page.getElementById("buttonSkipBuildView"); page = button.click(); text = page.asText(); assertTrue(text.indexOf("buildView") == -1); }
/** * Tests that the details of cargo with tracking Id DEF789 can be viewed through the admin * interface. */ @Test @RunAsClient public void testViewDetailsId4() { log.log( Level.INFO, "Starting automated test to view details for Id \"" + trackingId4 + "\" through admin interface."); try { System.out.println(landingPageResponse.getUrl()); // Stores the adminDashboard as a HtmlPage object. HtmlPage adminDashboard = landingPageResponse.getElementById("adminLandingLink").click(); Assert.assertThat( "Page title was not as expected for the admin dashboard. Expected \"Cargo Dashboard\" but actual was \"" + adminDashboard.getTitleText() + "\".", adminDashboard.getTitleText(), is("Cargo Dashboard")); // Stores the details page as a HtmlPage object. HtmlPage detailsPage = adminDashboard.getAnchorByText(trackingId4).click(); Assert.assertTrue( "Expected \"Not routed\" message was not found.", detailsPage.asText().contains("Not routed")); } catch (IOException ex) { Assert.fail( "An IOException was thrown during the test for class \"" + ViewDetailTest.class.getSimpleName() + "\" at method \"" + testName.getMethodName() + "\" with message: " + ex.getMessage()); } }
public static void main(String[] args) { WebClient client = new WebClient(BrowserVersion.CHROME); HtmlPage page = null; try { page = client.getPage("http://www.facebook.com"); System.out.println(page.getTitleText()); HtmlForm form = (HtmlForm) page.getElementById("login_form"); form.getInputByName("email").setValueAttribute("*****@*****.**"); form.getInputByName("pass").setValueAttribute("saburtalo16"); page = form.getInputByValue("Log In").click(); System.out.println(page.getTitleText()); HtmlTextArea statusText = (HtmlTextArea) page.getElementByName("xhpc_message_text"); statusText.click(); statusText.setText("I'm a robot"); HtmlButton post = (HtmlButton) page.getFirstByXPath("//button[@id=\"u_jsonp_3_4\"]/div/div[4]/div/ul/li[2]/button"); post.click(); } catch (Exception e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } }
public static HtmlPage trainStrength(HtmlPage page, int amount) throws IOException { System.out.println("Training " + amount + " strength..."); for (DomNode n : page.getElementById("divStrength").getDescendants()) { // System.out.println(n.toString()); HtmlTextInput textInput; HtmlSubmitInput submitInput; if (n.toString() .contains("HtmlTextInput[<input type=\"text\" value=\"1\" id=\"t\" name=\"t\">]")) { textInput = (HtmlTextInput) n; textInput.setValueAttribute(Integer.toString(amount)); System.out.println(textInput.toString()); } else if (n.toString() .contains("HtmlSubmitInput[<input type=\"submit\" value=\"Train\">]")) { submitInput = (HtmlSubmitInput) n; page = submitInput.click(); System.out.println(submitInput.toString()); } } /* System.out.println(this.user.getUsername()+"-"+"Training "+amount+" strength..."); HtmlTextInput amountInput = (HtmlTextInput) page.getByXPath("/html/body/div[4]/table/tbody/tr/td[2]/center/div[2]/div/div[2]/div[3]/div[1]/div[1]/div[2]/form/table/tbody/tr/td[1]/input[1]").get(0); amountInput.setValueAttribute(Integer.toString(amount)); HtmlElement e = (HtmlElement) page.getByXPath("/html/body/div[4]/table/tbody/tr/td[2]/center/div[2]/div/div[2]/div[3]/div[1]/div[1]/div[2]/form/table/tbody/tr/td[3]/input").get(0); e.click(); */ System.out.println(page.asText()); return page; }
protected void assertLoginPage() { assertNotNull( page.getElementById("tynamoLogin"), "Page doesn't contain login field. Not a login page."); assertEquals( "password", getAttribute("tynamoPassword", "type"), "Page doesn't contain password field. Not a login page."); assertEquals( "checkbox", getAttribute("tynamoRememberMe", "type"), "Page doesn't contain rememberMe field. Not a login page."); assertNotNull( page.getElementById("tynamoEnter"), "Page doesn't contain login form submit button. Not a login page."); }
@Test public void testRowRemoved() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/repeatRemoved.xhtml"); assertNotNull(page.getHtmlElementById("f:r:0:i")); HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("f:r:0:b"); page = button.click(); assertNull(page.getElementById("f:r:0:i")); }
// ------------------------------------------------------------ Test Methods public void testNoViewParamsWithJsp() throws Exception { HtmlPage page = getPage("/faces/view1.jsp"); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form:refreshWithRedirectParams"); page = button.click(); assertTrue(page.asText().contains("PAGE 2 OUTPUT")); }
/** * This test verifies that an attribute nameed 'value' can be successfully updated from a partial * response (over Ajax). */ @Test public void testScript() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/script.xhtml"); assertTrue(page.asXml().contains("SCRIPT EXECUTED!")); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form1:button1"); page = button.click(); assertTrue(page.asXml().contains("SCRIPT EXECUTED!")); }
/** * Saves changes made by clicking the save button * * @return {@link AlbumPage} */ public AlbumPage saveChanges() { HtmlSubmitInput saveButton = (HtmlSubmitInput) page.getElementById("saveButton"); try { saveButton.click(); } catch (IOException e) { e.printStackTrace(); } return this; }
/** * Cancel changes made by clicking the cancel button * * @return {@link AlbumListPage} */ public AlbumListPage cancelChanges() { HtmlSubmitInput cancelButton = (HtmlSubmitInput) page.getElementById("cancelButton"); try { cancelButton.click(); } catch (IOException e) { e.printStackTrace(); } return new AlbumListPage(webClient); }
@Test public void testConverterInstallation() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/issue1660.xhtml"); assertTrue(page.asXml().matches("(?s).*Simple\\s+value\\s+is\\s+VALUE1.*")); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button"); page = button.click(); assertTrue(page.asXml().matches("(?s).*Simple\\s+value\\s+is\\s+VALUE1.*")); }
@Test(groups = {"notLoggedIn"}) public void testLocalizedUserFilterDeny() throws Exception { // this test can fail either if acl rules don't correctly handle path matching with the // requested locale, // or that resulting login page is not correctly localized anymore (requested locale is lost) openPage("fi_FI/authc/cabinet"); assertLoginPage(); page.getElementById("tynamoEnter").asText().contains("Kirjaudu sisään"); }
@Test @Ignore public void test01() throws Exception { System.out.println("-------------------------------"); WebClient webClient = new WebClient(BrowserVersion.CHROME); try { WebClientOptions options = webClient.getOptions(); options.setThrowExceptionOnFailingStatusCode(false); options.setThrowExceptionOnScriptError(false); options.setCssEnabled(false); options.setJavaScriptEnabled(true); options.setTimeout(50000); // webClient.setAjaxController(new NicelyResynchronizingAjaxController()); HtmlPage pageOrgin = webClient.getPage("http://lvyou.baidu.com/jinhua/jingdian"); Thread.sleep(5000); DomNodeList<DomNode> pageNodes = pageOrgin.querySelectorAll(".pagination"); HtmlDivision pageDiv = (HtmlDivision) pageNodes.get(0); DomNodeList<HtmlElement> liElements = pageDiv.getElementsByTagName("li"); Integer pageSize = liElements.size() - 1; for (int pageNow = 0; pageNow < pageSize; pageNow++) { DomNodeList<HtmlElement> pageAnchors = liElements.get(pageNow).getElementsByTagName("a"); HtmlAnchor pageAnchor = (HtmlAnchor) pageAnchors.get(0); HtmlPage page = pageAnchor.click(); Thread.sleep(10000); DomElement jViewDom = page.getElementById("J-view-list-container"); DomNodeList<HtmlElement> lis = jViewDom.getElementsByTagName("li"); for (HtmlElement li : lis) { DomNodeList<DomNode> titleNodes = li.querySelectorAll(".title"); HtmlAnchor titleAnchor = (HtmlAnchor) titleNodes.get(0); System.out.println("---------------标题----------------"); log.debug("{}", titleAnchor.asText()); DomNodeList<DomNode> picNodes = li.querySelectorAll(".pic"); HtmlAnchor picAnchor = (HtmlAnchor) picNodes.get(0); System.out.println("---------------详情URL----------------"); String detailUrl = "http://lvyou.baidu.com" + picAnchor.getAttribute("href"); log.debug("{}", detailUrl); DomNodeList<HtmlElement> imgEelements = picAnchor.getElementsByTagName("img"); for (HtmlElement imgEelement : imgEelements) { System.out.println("---------------图片----------------"); log.debug("{}", imgEelement.getAttribute("src")); } DomNodeList<DomNode> sumNodes = li.querySelectorAll(".view-userSays"); HtmlDivision sumDiv = (HtmlDivision) sumNodes.get(0); DomNodeList<HtmlElement> sumElements = sumDiv.getElementsByTagName("p"); HtmlParagraph sumPara = (HtmlParagraph) sumElements.get(0); System.out.println("---------------摘要----------------"); log.debug("{}", sumPara.asText()); } } } finally { webClient.close(); } System.out.println("-------------------------------"); }
/** * Test to validate empty fields. * * <p>Note: this test is excluded on Tomcat because the included EL parser requires a System * property for this test to work, which would cause problems with other tests. See * http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html and look for COERCE_TO_ZERO */ @Test public void testValidateEmptyFields() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/index.xhtml"); if (page.getWebResponse().getResponseHeaderValue("Server") == null || !page.getWebResponse().getResponseHeaderValue("Server").startsWith("Apache-Coyote")) { page = webClient.getPage(webUrl + "faces/validateEmptyFields.xhtml"); HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("form:submitButton"); page = button.click(); assertTrue(page.asXml().contains("We got called!")); } }
@Test @Ignore public void test() throws Exception { System.out.println("-------------------------------"); WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setCssEnabled(false); webClient.getOptions().setJavaScriptEnabled(false); HtmlPage page = webClient.getPage("http://news.163.com/domestic/"); // DomNodeList<HtmlElement> elements = page.getElementBy System.out.println("---------------标题----------------"); DomNodeList<DomNode> domNodes = page.querySelectorAll(".item-top"); // log.debug("{}", domNodes); for (DomNode domNode : domNodes) { HtmlDivision htmlDivision = (HtmlDivision) domNode; DomNodeList<HtmlElement> aElements = htmlDivision.getElementsByTagName("a"); HtmlAnchor htmlAnchor = (HtmlAnchor) aElements.get(0); // HTMLHeadingElement htmlHeading2 = (HTMLHeadingElement) // htmlDivision.getElementsByTagName("h2"); // HtmlAnchor htmlAnchor = (HtmlAnchor) htmlDivision.getElementsByTagName("a"); log.debug("{}", htmlAnchor.asText()); log.debug("{}", htmlAnchor.getAttribute("href")); DomNodeList<HtmlElement> pElements = htmlDivision.getElementsByTagName("p"); HtmlParagraph htmlParagraph = (HtmlParagraph) pElements.get(0); log.debug("{}", htmlParagraph.asText()); DomNodeList<HtmlElement> iEelements = htmlDivision.getElementsByTagName("img"); for (HtmlElement iEelement : iEelements) { log.debug("{}", iEelement.getAttribute("src")); } String detailUrl = htmlAnchor.getAttribute("href"); if (detailUrl.equals("http://news.163.com/15/1215/17/BAT2L8RB00014JB6.html#f=dlist")) { HtmlPage detailPage = webClient.getPage(detailUrl); System.out.println("---------------正文----------------"); DomElement endTextElement = detailPage.getElementById("endText"); log.debug("{}", endTextElement.asText()); System.out.println("---------------图片----------------"); DomNodeList<DomNode> imgNodes = endTextElement.querySelectorAll(".f_center"); for (DomNode imgNode : imgNodes) { HtmlParagraph imgpara = (HtmlParagraph) imgNode; DomNodeList<HtmlElement> endImgs = imgpara.getElementsByTagName("img"); for (HtmlElement endImg : endImgs) { log.debug("{}", endImg.getAttribute("src")); } } } } webClient.close(); System.out.println("-------------------------------"); }
public static HtmlPage solveCaptcha(HtmlPage page) throws Exception { System.out.println("Solving captcha..."); String url = page.getUrl().toString(); page = wc.getPage(url + "?bypass=1"); HtmlImage captchaImage = (HtmlImage) page.getElementById("recaptcha_image").getFirstChild(); captchaImage.saveAs(new File("captcha-image.jpg")); CaptchaSolver captchaSolver = new CaptchaSolver(new SocketClient("trialaccount", "Cappie1!"), "captcha-image.jpg"); captchaSolver.run(); Captcha captcha = captchaSolver.getCaptcha(); HtmlTextInput textField = (HtmlTextInput) page.getElementById("recaptcha_response_field"); textField.setValueAttribute(captcha.text); HtmlElement element = (HtmlElement) page.getElementByName("submit"); page = element.click(); System.out.println("Captcha entered."); return wc.getPage(url); }
@Test public void canDropFailureCause() throws Exception { ClaimBuildAction action = applyClaimWithFailureCauseSelected("claim", CAUSE_NAME_2, REASON, CAUSE_DESCRIPTION_2); HtmlPage page = whenNavigatingtoClaimPage(); page.getElementById("dropClaim").click(); page = whenNavigatingtoClaimPage(); assertThat(action.isClaimed(), is(false)); assertTrue(page.asXml().contains(IDENTIFIED_PROBLEMS)); assertTrue(page.asXml().contains("No identified problem")); }
@Test public void testActionPhases() throws Exception { HtmlPage firstPage = getWebClient("/action").getPage(); // reload so we get a postback that visits all the phases HtmlPage secondPage = firstPage.getElementById("form:reload").click(); String secondPageContent = secondPage.getWebResponse().getContentAsString(); assertContains(secondPageContent, "Action 1 = [RESTORE_VIEW]"); assertContains(secondPageContent, "Action 2 = [RENDER_RESPONSE]"); assertContains(secondPageContent, "Action 3 = [INVOKE_APPLICATION]"); }
@Test public void shouldIncludeUnloadJSInSavedReport() throws Exception { File jsonFile = new File(getReportDir() + "/jscoverage.json"); if (jsonFile.exists()) jsonFile.delete(); HtmlPage page = webClient.getPage("http://localhost:9001/jscoverage.html?index.html"); page.getHtmlElementById("summaryTab").click(); webClient.waitForBackgroundJavaScript(2000); assertEquals("77%", page.getElementById("summaryTotal").getTextContent()); verifyCoverage(page, "/root.js", "80%", "50%", "100%"); verifyCoverage(page, "/level1/level1.js", "75%", "50%", "N/A"); page.getHtmlElementById("storeTab").click(); webClient.waitForBackgroundJavaScript(500); HtmlElement storeButton = page.getHtmlElementById("storeButton"); storeButton.click(); webClient.waitForBackgroundJavaScript(2000); String result = page.getElementById("storeDiv").getTextContent(); assertThat( result, containsString("Coverage data stored at " + new File(getReportDir()).getPath())); String json = ioUtils.toString(jsonFile); assertThat(json, containsString("/root.js")); assertThat(json, containsString("/level1/level2/level2.js")); String url = "file:///" + new File(getReportDir() + "/jscoverage.html").getAbsolutePath(); page = webClient.getPage(url); webClient.waitForBackgroundJavaScript(1000); assertEquals("53%", page.getElementById("summaryTotal").getTextContent()); assertEquals("33%", page.getElementById("branchSummaryTotal").getTextContent()); assertEquals("50%", page.getElementById("functionSummaryTotal").getTextContent()); verifyCoverage(page, "/root.js", "80%", "50%", "100%"); verifyCoverage(page, "/level1/level1.js", "75%", "50%", "N/A"); verifyCoverage(page, "/level1/level2/level2.js", "0%", "0%", "0%"); }