Package com.gargoylesoftware.htmlunit.html

Examples of com.gargoylesoftware.htmlunit.html.HtmlPage


    executeAllPageTests("opensocial-templates/ost_test");
  }

  @Test
  public void testFailCaja() throws Exception {
    HtmlPage page = executePageTest("failCajaTest", null);
    NodeList bodyList = page.getElementsByTagName("body");

    // Result should contain just one body
    assertEquals(1, bodyList.getLength());
    DomNode body = (DomNode) bodyList.item(0);
View Full Code Here


    }
  }

  @Test
  public void testPipelining() throws Exception {
    HtmlPage page = executePageTest("pipeliningTest", null);
    JSONArray array = new JSONArray(page.asText());
    assertEquals(3, array.length());
    Map<String, JSONObject> jsonObjects = Maps.newHashMap();
    for (int i = 0; i < array.length(); i++) {
      JSONObject jsonObj = array.getJSONObject(i);
      assertTrue(jsonObj.has("id"));
View Full Code Here

    executeAllPageTests("osapi/batchTest", true /* caja */);
  }

  @Test
  public void testTemplateRewrite() throws Exception {
    HtmlPage page = executePageTest("templateRewriter", null);

    // Verify that iteration attributes were processed
    HtmlElement attrs = page.getElementById("attrs");
    List<HtmlElement> attrsList = attrs.getElementsByTagName("li");
    assertEquals(3, attrsList.size());

    Element element = page.getElementById("id0");
    assertNotNull(element);
    assertEquals("Jane", element.getTextContent().trim());

    element = page.getElementById("id2");
    assertNotNull(element);
    assertEquals("Maija", element.getTextContent().trim());

    // Verify that the repeatTag was processed
    HtmlElement repeat = page.getElementById("repeatTag");
    List<HtmlElement> repeatList = repeat.getElementsByTagName("li");
    assertEquals(1, repeatList.size());
    assertEquals("George", repeatList.get(0).getTextContent().trim());

    // Verify that the ifTag was processed
    HtmlElement ifTag = page.getElementById("ifTag");
    List<HtmlElement> ifList = ifTag.getElementsByTagName("li");
    assertEquals(3, ifList.size());
    assertEquals(1, page.getElementsByTagName("b").getLength());
    assertEquals(1, ifList.get(2).getElementsByTagName("b").size());

    Element jsonPipeline = page.getElementById("json");
    assertEquals("value", jsonPipeline.getTextContent().trim());

    Element textPipeline = page.getElementById("text");
    assertEquals("{\"key\": \"value\"}", textPipeline.getTextContent().trim());

    // Test of oncreate
    Element oncreateSpan = page.getElementById("mutate");
    assertEquals("mutated", oncreateSpan.getTextContent().trim());

    assertEquals("45", page.getElementById("sum").getTextContent().trim());
    assertEquals("25", page.getElementById("max").getTextContent().trim());
  }
View Full Code Here

    assertEquals("25", page.getElementById("max").getTextContent().trim());
  }

  @Test
  public void testTemplateLibrary() throws Exception {
    HtmlPage page = executeAllPageTests("templateLibrary");
    String pageXml = page.asXml();
    assertTrue(pageXml.replaceAll("[\n\r ]", "").contains("p{color:red}"));

    Node paragraph = page.getElementsByTagName("p").item(0);
    assertEquals("Hello world", paragraph.getTextContent().trim());
  }
View Full Code Here

        WebClient client = new WebClient();
        client.setRedirectEnabled(true);

        // Going to have the WebClient connect to this URL
        URL url = new URL(testUrl);
        HtmlPage page = (HtmlPage) client.getPage(url);
        // System.out.println(page.getTitleText());

        // Check response code
        WebResponse resp = page.getWebResponse();
        assertTrue(resp.getStatusCode() <= 200);
        List forms = page.getForms();
       

        HtmlPage resultPage = null;
        WebResponse resultResponse= null;
        boolean formfound = false;
        for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
            HtmlForm form = (HtmlForm) iter.next();

            if ("loginAction".equals(form.getActionAttribute())) {
                formfound = true;
                HtmlInput login = form.getInputByName("login");
                HtmlInput password = form.getInputByName("password");
                login.setValueAttribute("test");
                password.setValueAttribute("password");

                resultPage = (HtmlPage) form.submit();
                // Check response from servlet
                resultResponse = resultPage.getWebResponse();
                assertTrue(resultResponse.getStatusCode() <= 200);

             
                String response = resultResponse.getContentAsString();
                assertTrue(-1 != response.indexOf("Account Information for"));
                assertTrue(-1 != response.indexOf("Test"));
                assertTrue(-1 != response.indexOf("134-42-6231"));
                assertTrue(-1 != response.indexOf("123.43"));
                assertTrue(-1 != response.indexOf("134-43-3941"));
                assertTrue(-1 != response.indexOf("23.12"));

                Pattern pat = Pattern.compile("LU.*7", Pattern.DOTALL);
                Matcher test = pat.matcher(response);
                assertTrue(test.find());
            }

        }
        forms = resultPage.getForms();
       
        formfound = false;
        for(Iterator iter = forms.iterator();  formfound != true && iter.hasNext();) {
            HtmlForm form = (HtmlForm) iter.next();

            if ("purchaseStock.jsp".equals(form.getActionAttribute())) {
                formfound = true;
                resultPage = (HtmlPage) form.submit();
            }

        }
        assertTrue(formfound);
        forms = resultPage.getForms();
        formfound = false;
        for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
            HtmlForm form = (HtmlForm) iter.next();

            if ("FormServlet".equals(form.getActionAttribute())) {
                formfound = true;

                HtmlInput login = form.getInputByName("symbol");
                HtmlInput password = form.getInputByName("quantity");
                login.setValueAttribute("EDS");
                password.setValueAttribute("131");
               
                resultPage = (HtmlPage) form.submit();
                // Check response from servlet
                resultResponse = resultPage.getWebResponse();
                assertTrue(resultResponse.getStatusCode() <= 200);

            
                String response = resultResponse.getContentAsString();
                assertTrue(-1 != response.indexOf("Account Information for"));
                assertTrue(-1 != response.indexOf("Test"));
                assertTrue(-1 != response.indexOf("134-42-6231"));
                assertTrue(-1 != response.indexOf("123.43"));
                assertTrue(-1 != response.indexOf("134-43-3941"));
                assertTrue(-1 != response.indexOf("23.12"));

                Pattern pat = Pattern.compile("LU.*7", Pattern.DOTALL);
                Matcher test = pat.matcher(response);
                assertTrue(test.find());
                pat = Pattern.compile("EDS.*131", Pattern.DOTALL);
                test = pat.matcher(response);
                assertTrue(test.find());

            }

        }
        assertTrue(formfound);
        forms = resultPage.getForms();
        formfound = false;
        for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
            HtmlForm form = (HtmlForm) iter.next();

            if ("stockSale.jsp".equals(form.getActionAttribute())) {
//                System.err.println(form.asText());
               
               
               
                Pattern pat = Pattern.compile("EDS.*131", Pattern.DOTALL);
               
                Matcher test = pat.matcher(form.asText());
                if(!test.find()) continue;

               
               
               
                formfound = true;
                resultPage = (HtmlPage) form.submit();
                // Check response from servlet
                resultResponse = resultPage.getWebResponse();
                assertTrue(resultResponse.getStatusCode() <= 200);


            }

        }
        forms = resultPage.getForms();
       
       
       
        formfound = false;
        for(Iterator iter = forms.iterator();  formfound != true && iter.hasNext();) {
            HtmlForm form = (HtmlForm) iter.next();

            if ("FormServlet".equals(form.getActionAttribute())) {
                formfound = true;

               
                HtmlInput password = form.getInputByName("quantity");
               
                password.setValueAttribute("131");

                resultPage = (HtmlPage) form.submit();
                // Check response from servlet
                resultResponse = resultPage.getWebResponse();
                assertTrue(resultResponse.getStatusCode() <= 200);

               
                String response = resultResponse.getContentAsString();
                assertTrue(-1 != response.indexOf("Account Information for"));
                assertTrue(-1 != response.indexOf("Test"));
                assertTrue(-1 != response.indexOf("134-42-6231"));
                assertTrue(-1 != response.indexOf("123.43"));
                assertTrue(-1 != response.indexOf("134-43-3941"));
                assertTrue(-1 != response.indexOf("23.12"));

                Pattern pat = Pattern.compile("LU.*7", Pattern.DOTALL);
                Matcher test = pat.matcher(response);
                assertTrue(test.find());
                // pat = Pattern.compile("EDS.*131", Pattern.DOTALL);
                // test = pat.matcher(response);
                //                assertFalse(test.find());


            }

        }
        assertTrue(formfound);
       
        forms = resultPage.getForms();
        formfound = false;
        for (Iterator iter = forms.iterator(); formfound != true && iter.hasNext();) {
            HtmlForm form = (HtmlForm) iter.next();

            if ("loginAction".equals(form.getActionAttribute())) {
View Full Code Here

    System.err.println("Running: testcase:");
    // New HTMLunit web client
    WebClient client = new WebClient();
    // Going to have the WebClient connect to this URL
    URL url = new URL(testUrl);
    HtmlPage page = (HtmlPage)client.getPage(url);
    //System.out.println(page.getTitleText());
   
    // Check response code
    WebResponse resp = page.getWebResponse();
    assertTrue(resp.getStatusCode() <= 200);
    List forms = page.getForms();
    Iterator iter = forms.iterator();
   
    // Iterate over all forms on page, should only be one.
    while(iter.hasNext())
    {
View Full Code Here

        webClient.setThrowExceptionOnScriptError(false);
        //webClient.waitForBackgroundJavaScript(100000);
        //webClient.waitForBackgroundJavaScriptStartingBefore(100000);
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());

        HtmlPage page = (HtmlPage) webClient.getPage("http://localhost:8080/store/store.html");

        HtmlForm form = (HtmlForm) page.getFormByName("catalogForm");

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
View Full Code Here

    private URL url;

    @Test
    public void shouldIncludeOrExcludeBodyCorrectly() throws IOException {
        WebClient client = new WebClient();
        HtmlPage page = client.getPage(url + "jsp-taglib-test.jsp");
        assertThat(page.asText())
            .contains("Feature [ACTIVE_FEATURE] is active")
            .doesNotContain("Feature [INACTIVE_FEATURE] is active");
    }
View Full Code Here

    }

    @Test
    public void shouldIncludeOrExcludeBodyCorrectlyInverseCondition() throws IOException {
        WebClient client = new WebClient();
        HtmlPage page = client.getPage(url + "jsp-taglib-inverse-test.jsp");
        assertThat(page.asText())
                .contains("Feature [INACTIVE_FEATURE] is inactive")
                .doesNotContain("Feature [ACTIVE_FEATURE] is inactive");
    }
View Full Code Here

    @Test
    public void testJSFFeatureMap() throws IOException, Exception {

        WebClient client = new WebClient();
        HtmlPage page = client.getPage(url + "index.jsf");

        // this part of the page is rendered
        assertTrue(page.asText().contains("Text for ENABLED feature!"));

        // this part is disabled
        assertFalse(page.asText().contains("Text for DISABLED feature!"));

        // one div can be found the other not
        assertNotNull(page.getElementById("enabledDiv"));
        assertNull(page.getElementById("disabledDiv"));

    }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.html.HtmlPage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.