@JsfTest(JsfVersion.JSF_2_2_1) @Test public void testNoELEvaluation() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/hOutputStylesheet.xhtml"); assertEquals(200, page.getWebResponse().getStatusCode()); HtmlElement button = page.getHtmlElementById("form:submit"); page = button.click(); assertEquals(200, page.getWebResponse().getStatusCode()); }
@Test public void testIssue1825() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/issue1825.xhtml"); HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("form:button"); page = button.click(); assertEquals(200, page.getWebResponse().getStatusCode()); button = (HtmlSubmitInput) page.getHtmlElementById("form:button"); page = button.click(); assertEquals(200, page.getWebResponse().getStatusCode()); }
/** * 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!")); } }
/** * Verify that if an initial request comes to a FacesSevlet mapped using a prefix path, that the * client is redirected to the context root. Additionally verify that after request to a * particular view has been made, if a subsequent request is made to the prefix path, context root * redirection occurs. */ public void testVerifyPathBehavior() throws Exception { final String welcomePage = "WELCOMEPAGE"; HtmlPage page = getPage("/faces"); WebResponse response = page.getWebResponse(); assertTrue(welcomePage.equals(response.getContentAsString().trim())); // Ok, now get a page HtmlPage textPage = getHtmlPage("/faces/hello.jsp"); response = textPage.getWebResponse(); assertTrue("/hello.jsp PASSED".equals(response.getContentAsString().trim())); page = getPage("/faces"); response = page.getWebResponse(); assertTrue("WELCOMEPAGE".equals(response.getContentAsString().trim())); }
/** @throws Exception if an error occurs */ @Test public void preventDefault() throws Exception { final String html = "<html><head><title>First</title>\n" + "<script>\n" + "function block(e) {\n" + " if (e && e.preventDefault)\n" + " e.preventDefault();\n" + " else\n" + " return false;\n" + "}\n" + "\n" + "function test() {\n" + " document.getElementById('myForm').onsubmit = block;\n" + "}\n" + "</script>\n" + "</head><body onload='test()'>\n" + "<form id='myForm' action='doesnt_exist.html'>\n" + " <input type='submit' id='mySubmit' value='Continue'></p>\n" + "</form>" + "</body></html>"; final HtmlPage page = loadPageWithAlerts(html); final HtmlPage page2 = page.getHtmlElementById("mySubmit").click(); assertEquals(getDefaultUrl(), page2.getWebResponse().getWebRequest().getUrl()); }
Result proceed() { HtmlPage resultPage = null; try { resultPage = proceedImpl(); } catch (IOException e) { return Result.FAILURE_COULD_NOT_LOAD_PAGE; } if (resultPage == null) { return Result.FAILURE_UNEXPECTED_LAYOUT; } this.followUpPage = resultPage; WebResponse response = resultPage.getWebResponse(); if (response == null) { return Result.FAILURE_COULD_NOT_LOAD_PAGE; } if (responseValidator.isExceptedResponse(response)) { this.result = produceResult(resultPage); return Result.SUCCESS; } return Result.FAILURE_WRONG_RESPONSE; }
public void testImageInsideCollection() throws Exception { execute("CRUD.new"); execute("Collection.new", "viewObject=xava_view_section0_ingredients"); execute("ImageEditor.changeImage", "newImageProperty=image"); assertNoErrors(); assertAction("LoadImage.loadImage"); String imageUrl = System.getProperty("user.dir") + "/test-images/cake.gif"; setFileValue("newImage", imageUrl); execute("LoadImage.loadImage"); assertNoErrors(); HtmlPage page = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage(); URL url = page.getWebResponse().getRequestSettings().getUrl(); String urlPrefix = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort(); HtmlImage image = (HtmlImage) page.getElementsByName(decorateId("image")).get(0); String imageURL = null; if (image.getSrcAttribute().startsWith("/")) { imageURL = urlPrefix + image.getSrcAttribute(); } else { String urlBase = Strings.noLastToken(url.getPath(), "/"); imageURL = urlPrefix + urlBase + image.getSrcAttribute(); } WebResponse response = getWebClient().getPage(imageURL).getWebResponse(); assertTrue("Image not obtained", response.getContentAsString().length() > 0); assertEquals("Result is not an image", "image", response.getContentType()); }
private void search(SearchEngine se) { try { initializeJdbc(); final WebClient webClient = new WebClient( getBrowserVersionFromName(se.getDefaultBrowser())); // BrowserVersion.FIREFOX_24); // webClient.getOptions().setThrowExceptionOnScriptError(false); String htmlSource; HtmlPage searchResultPage = null; // String baseUrl = url; int numberOfUrlsExtracted; searchResultPage = clickSearchButtonMainPage(webClient, se); htmlSource = searchResultPage.getWebResponse().getContentAsString(); numberOfUrlsExtracted = ExtractAndInsertSeedUrls(searchResultPage, htmlSource, 1, 0, se.getName()); target.dispatchEvent(new EventSearchWorker(target, 1)); try { for (int i = 1; i < maxPage; i++) { HtmlAnchor ha = (HtmlAnchor) getNextButtonOrLink(searchResultPage, se.getNextButtonIdentifier()); searchResultPage = ha.click(); htmlSource = searchResultPage.getWebResponse().getContentAsString(); numberOfUrlsExtracted = ExtractAndInsertSeedUrls( searchResultPage, htmlSource, i + 1, numberOfUrlsExtracted, se.getName()); // nextUrl = getNextUrl(b, se, baseUrl); target.dispatchEvent(new EventSearchWorker(target, 1)); Random r = new Random(); int randomSleepTime = r.nextInt(2000) + 200; // minimum 200 ms max 2200 ms Thread.sleep(randomSleepTime); } // fw.close(); } catch (Exception ex) { String x = ex.getMessage(); } webClient.closeAllWindows(); } catch (Exception ex) { String x = ex.getMessage(); } }
@Test public void testReplaceVDL() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/issue2405.xhtml"); String text = page.asText(); assertEquals(200, page.getWebResponse().getStatusCode()); assertTrue( text.indexOf( "The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>") == -1); }
@JsfTest(JsfVersion.JSF_2_2_5) @Test public void testSetForEach() throws Exception { webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage page = webClient.getPage(webUrl + "faces/setForEach.xhtml"); assertEquals(200, page.getWebResponse().getStatusCode()); assertTrue(page.asXml().indexOf("foo") == -1); assertTrue(page.asXml().indexOf("bar") != -1); assertTrue(page.asXml().indexOf("baz") != -1); }
/** * 抓取一个页面 * * @param url * @param fileName * @throws Exception void * @author wx */ private void fetchPage(String url, String fileName) throws Exception { HtmlPage page = client.getPage(url); // html文本 String html = page.getWebResponse().getContentAsString(); // html = getStaticResources(page, html); html = changeStaticResources(page, html, url); saveHtmlPage(html, fileName); }
@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 testDataList() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/datalist.xhtml"); HtmlElement elem = page.getHtmlElementById("colors"); String xml = elem.asXml(); assertTrue(xml.contains("<datalist")); assertTrue(xml.contains("id=\"" + "colors" + "\"")); WebResponse resp = page.getWebResponse(); String text = resp.getContentAsString(); assertTrue(text.contains("<option id=" + '"' + "r" + '"' + " value=" + '"' + "red" + '"')); assertTrue(text.contains("<option id=" + '"' + "b" + '"' + " value=" + '"' + "blue" + '"')); assertTrue(text.contains("<option id=" + '"' + "g" + '"' + " value=" + '"' + "green" + '"')); }
public void testCopy() throws Exception { String fromPageName = uniqueWikiPageName("CopyTestFrom"); String toPageName = uniqueWikiPageName("CopyTestTo"); editWikiPage(fromPageName, "Catchy tunes", "", "Whatever", true); HtmlPage page = getWikiPage(fromPageName); page = (HtmlPage) page.getAnchorByName("copy").click(); HtmlForm form = page.getFormByName("copyForm"); form.getInputByName("toPage").setValueAttribute(toPageName); page = (HtmlPage) form.getButtonByName("copy").click(); assertTrue( page.getWebResponse().getWebRequest().getUrl().toURI().getPath().contains(toPageName)); assertTrue(page.asText().contains("Catchy tunes")); page = getWikiPage(fromPageName); assertTrue(page.asText().contains("Catchy tunes")); }
@Test public void testRedirect() throws Exception { RedirectRefreshHandler handler = new RedirectRefreshHandler(); client.setRefreshHandler(handler); HtmlPage redirect = (HtmlPage) client.getPage(BASE + "/sp/priv1.jsp"); assertEquals(200, redirect.getWebResponse().getStatusCode()); assertTrue( handler .url .toString() .startsWith( idpMetadata .getFirstMetadata() .getSingleSignonServiceLocation(SAMLConstants.SAML2_REDIRECT_BINDING_URI))); }
private HtmlPage doStory2Button(HtmlPage page, int storyNum) throws Exception { String pageText = null; // Click the "story2" button, ensure you get // to the story 2 page HtmlSubmitInput button = (HtmlSubmitInput) page.getHtmlElementById("story2RememberSelectionNavCase"); page = (HtmlPage) button.click(); pageText = page.asText(); URL requestUrl = page.getWebResponse().getRequestUrl(); // Assert that the queryString is in the reqeust URL. assertTrue(-1 != requestUrl.getQuery().indexOf("bar=foo")); assertTrue(-1 != pageText.indexOf("Story 2")); assertTrue(-1 != pageText.indexOf("bar is:foo")); return page; }
public void testChangeImage() throws Exception { addImage(); HtmlPage page = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage(); URL url = page.getWebResponse().getRequestSettings().getUrl(); String urlPrefix = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort(); HtmlImage image = (HtmlImage) page.getElementsByName(decorateId("photo")).get(0); String imageURL = null; if (image.getSrcAttribute().startsWith("/")) { imageURL = urlPrefix + image.getSrcAttribute(); } else { String urlBase = Strings.noLastToken(url.getPath(), "/"); imageURL = urlPrefix + urlBase + image.getSrcAttribute(); } WebResponse response = getWebClient().getPage(imageURL).getWebResponse(); assertTrue("Image not obtained", response.getContentAsString().length() > 0); assertEquals("Result is not an image", "image", response.getContentType()); }
private void ProcessTest(WebTest test) { HtmlPage page = null; // Orville.LOG().info(String.format("Executing test %s\n", event)); WebClient webClient = new WebClient(); webClient.setRefreshHandler(new ThreadedRefreshHandler()); webClient.getOptions().setJavaScriptEnabled(false); try { if (test.getMethod().toLowerCase().equals("post")) { WebRequest request = new WebRequest(UrlUtils.toUrlUnsafe(test.getUrlString()), HttpMethod.POST); request.setRequestParameters(new ArrayList<NameValuePair>()); for (Map.Entry<String, String> entry : test.getPostData().entrySet()) { request.getRequestParameters().add(new NameValuePair(entry.getKey(), entry.getValue())); } page = webClient.getPage(request); } else { page = webClient.getPage(test.getUrlString()); } ProcessResult(test, page.getWebResponse()); } catch (FailingHttpStatusCodeException fsc) { Orville.LOG() .warning( String.format( "Failing HTTP Status code caught executing the test command: %s\n", fsc.getMessage())); } catch (IOException ioe) { Orville.LOG() .warning( String.format( "IO Exception caught executing the test command: %s\n", ioe.getMessage())); } webClient.closeAllWindows(); }
public void testDeleteImage() throws Exception { addImage(); execute("ImageEditor.deleteImage", "newImageProperty=photo"); assertNoErrors(); HtmlPage page = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage(); URL url = page.getWebResponse().getRequestSettings().getUrl(); String urlPrefix = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort(); HtmlImage image = (HtmlImage) page.getElementsByName(decorateId("photo")).get(0); String imageURL = null; if (image.getSrcAttribute().startsWith("/")) { imageURL = urlPrefix + image.getSrcAttribute(); } else { String urlBase = Strings.noLastToken(url.getPath(), "/"); imageURL = urlPrefix + urlBase + image.getSrcAttribute(); } WebResponse response = getWebClient().getPage(imageURL).getWebResponse(); assertTrue("Image obtained", response.getContentAsString().length() == 0); }
public void test1() throws Exception { FreeStyleProject p = createFreeStyleProject(); p.getBuildersList() .add( new TestBuilder() { @Override public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { listener.getLogger().println("http://www.sun.com/"); listener.getLogger().println("<http://www.kohsuke.org/>"); listener.getLogger().println("<a href='http://www.oracle.com/'>"); return true; } }); FreeStyleBuild b = buildAndAssertSuccess(p); HtmlPage c = createWebClient().getPage(b, "console"); String rsp = c.getWebResponse().getContentAsString(); assertTrue(rsp, rsp.contains("<a href='http://www.sun.com/'>http://www.sun.com/</a>")); assertTrue(rsp, rsp.contains("<a href='http://www.kohsuke.org/'>http://www.kohsuke.org/</a>")); assertTrue(rsp, rsp.contains("<a href='http://www.oracle.com/'>http://www.oracle.com/</a>")); }
public void testUnicodeEscapingTrue() throws Exception { client.addRequestHeader("Accept-Encoding", "UTF-8"); HtmlPage page = getPage("/faces/indexUTF.jsp?escape=true"); assertTrue( "Title should contain the unicode characters '\u1234' and '\u00c4'.", page.getWebResponse().getContentAsString().contains("a\u1234a") && !page.getWebResponse().getContentAsString().contains("aሴa") && page.getWebResponse().getContentAsString().contains("b\u00c4b") && !page.getWebResponse().getContentAsString().contains("bÄb")); client.addRequestHeader("Accept-Encoding", "US-ASCII"); page = getPage("/faces/indexUSASCII.jsp?escape=true"); assertTrue( "Title should contain the unicode characters replaced by ?.", !page.getWebResponse().getContentAsString().contains("a\u1234a") && page.getWebResponse().getContentAsString().contains("a?a") && !page.getWebResponse().getContentAsString().contains("b\u00c4b") && page.getWebResponse().getContentAsString().contains("b?b")); client.addRequestHeader("Accept-Encoding", "ISO-8859-1"); page = getPage("/faces/indexISO8859_1.jsp?escape=true"); assertTrue( "Title should contain the unicode character replaced by ? but the correct iso character.", !page.getWebResponse().getContentAsString().contains("a\u1234a") && page.getWebResponse().getContentAsString().contains("a?a") && page.getWebResponse().getContentAsString().contains("b\u00c4b") && !page.getWebResponse().getContentAsString().contains("bÄb")); }
public void testUnicodeEscapingFalse() throws Exception { client.addRequestHeader("Accept-Encoding", "UTF-8"); HtmlPage page = getPage("/faces/indexUTF.jsp?escape=false"); assertTrue( "Title should contain the escaped unicode characters only.", !page.getWebResponse().getContentAsString().contains("a\u1234a") && page.getWebResponse().getContentAsString().contains("aሴa") && !page.getWebResponse().getContentAsString().contains("b\u00c4b") && page.getWebResponse().getContentAsString().contains("bÄb")); client.addRequestHeader("Accept-Encoding", "US-ASCII"); page = getPage("/faces/indexUSASCII.jsp?escape=false"); assertTrue( "Title should contain the escaped unicode characters only.", !page.getWebResponse().getContentAsString().contains("a\u1234a") && page.getWebResponse().getContentAsString().contains("aሴa") && !page.getWebResponse().getContentAsString().contains("b\u00c4b") && page.getWebResponse().getContentAsString().contains("bÄb")); client.addRequestHeader("Accept-Encoding", "ISO-8859-1"); page = getPage("/faces/indexISO8859_1.jsp?escape=false"); assertTrue( "Title should contain the escaped unicode characters only.", !page.getWebResponse().getContentAsString().contains("a\u1234a") && page.getWebResponse().getContentAsString().contains("aሴa") && !page.getWebResponse().getContentAsString().contains("b\u00c4b") && page.getWebResponse().getContentAsString().contains("bÄb")); }
private String getLocation() { return page.getWebResponse().getWebRequest().getUrl().toString(); }
@Test public void testAttributeBooleanPrimitiveWithDefault() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/attributeBooleanPrimitiveWithDefault.xhtml"); assertEquals(200, page.getWebResponse().getStatusCode()); }
@Test public void testViewRootConstractsEL() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/viewRootContractsEL.xhtml"); assertEquals(200, page.getWebResponse().getStatusCode()); }
public static void savePage(String path) { // path = transformPath(path); if (!Main.list.contains(path) && path.contains("https://www.darts-ip.com")) { System.out.println(""); System.out.println("================================================="); System.out.println(""); System.out.println(path); System.out.println(""); Main.list.add(path); String content = ""; String fileName = ""; HtmlPage page = null; // ----------HTML-UNIT---------- try { WebClient webClient = new WebClient(); webClient.getOptions().setThrowExceptionOnScriptError(false); page = webClient.getPage(path); WebResponse response = page.getWebResponse(); content = response.getContentAsString(); fileName = path + ".html"; } catch (Exception e) { System.out.println(""); System.out.println("ERROR in Page.savePage #HTML-UNIT"); System.out.println(e); System.out.println(""); } // ----------SAVE-HTML-FILE---------- try { PrintWriter writer = new PrintWriter(fileName, "UTF-8"); writer.print(content); writer.close(); } catch (Exception e) { System.out.println(""); System.out.println("ERROR in ERROR in Page.savePage #SAVE-HTML-FILE"); System.out.println(e); System.out.println(""); } // ----------ZIP-HTML-FILE---------- try { FileInputStream fi = new FileInputStream(fileName); BufferedInputStream buffi = new BufferedInputStream(fi, Main.BUFFER); ZipEntry entry = new ZipEntry(fileName); Main.out.putNextEntry(entry); int count; while ((count = buffi.read(Main.data, 0, Main.BUFFER)) != -1) { Main.out.write(Main.data, 0, count); } Main.out.closeEntry(); buffi.close(); } catch (Exception e) { System.out.println(""); System.out.println("ERROR in Page.savePage #ZIP-HTML-FILE"); System.out.println(e); System.out.println(""); } // ----------DELETE-TMP-FILE---------- try { new File(fileName).delete(); } catch (Exception e) { System.out.println(""); System.out.println("ERROR in Page.savePage #DELETE-TMP-FILE"); System.out.println(e); System.out.println(""); } System.out.println(""); System.out.println("================================================="); // ----------EXPLORE-LINKS---------- exploreLinks(page); } }
@Test(groups = {"notLoggedIn"}) public void testNotFoundRule() throws Exception { openPage("hidden/something"); assertEquals(404, page.getWebResponse().getStatusCode()); }