Search in sources :

Example 1 with HtmlDefinitionDescription

use of com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription in project maven-doxia-sitetools by apache.

the class NestedItemsVerifier method verify.

/**
 * {@inheritDoc}
 */
public void verify(String file) throws Exception {
    HtmlPage page = htmlPage(file);
    assertNotNull(page);
    HtmlElement element = page.getHtmlElementById("contentBox");
    assertNotNull(element);
    HtmlDivision division = (HtmlDivision) element;
    assertNotNull(division);
    Iterator<HtmlElement> elementIterator = division.getHtmlElementDescendants().iterator();
    // ----------------------------------------------------------------------
    // Verify link
    // ----------------------------------------------------------------------
    HtmlSection section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
    assertNotNull(h2);
    assertEquals("List Section", h2.asText().trim());
    HtmlAnchor a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("List_Section", a.getAttribute("name"));
    // ----------------------------------------------------------------------
    // Unordered lists
    // ----------------------------------------------------------------------
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    HtmlHeading4 h4 = (HtmlHeading4) elementIterator.next();
    assertNotNull(h4);
    assertEquals("Unordered lists", h4.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("Unordered_lists", a.getAttribute("name"));
    HtmlParagraph p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Below is an unordered list, followed by six paragraphs.", p.asText().trim());
    HtmlUnorderedList ul = (HtmlUnorderedList) elementIterator.next();
    assertNotNull(ul);
    HtmlListItem li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 1.", li.getFirstChild().asText().trim());
    ul = (HtmlUnorderedList) elementIterator.next();
    assertNotNull(ul);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Item 11.", p.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Item 12.", p.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 13.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 14.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 2.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 3.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 4.", li.getFirstChild().asText().trim());
    ul = (HtmlUnorderedList) elementIterator.next();
    assertNotNull(ul);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 41.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 42.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 43.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 44.", li.getFirstChild().asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 1 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 2 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 3 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 4 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 5 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 6 below list.", p.asText().trim());
    // ----------------------------------------------------------------------
    // Ordered lists
    // ----------------------------------------------------------------------
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h4 = (HtmlHeading4) elementIterator.next();
    assertNotNull(h4);
    assertEquals("Ordered lists", h4.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("Ordered_lists", a.getAttribute("name"));
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Below is an ordered list, followed by six paragraphs.", p.asText().trim());
    HtmlOrderedList ol = (HtmlOrderedList) elementIterator.next();
    assertNotNull(ol);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 1.", li.getFirstChild().asText().trim());
    ol = (HtmlOrderedList) elementIterator.next();
    assertNotNull(ol);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 11.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 12.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 13.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 14.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 2.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 3.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 4.", li.getFirstChild().asText().trim());
    ol = (HtmlOrderedList) elementIterator.next();
    assertNotNull(ol);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 41.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 42.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 43.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 44.", li.getFirstChild().asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 1 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 2 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 3 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 4 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 5 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 6 below list.", p.asText().trim());
    // ----------------------------------------------------------------------
    // Definition lists
    // ----------------------------------------------------------------------
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h4 = (HtmlHeading4) elementIterator.next();
    assertNotNull(h4);
    assertEquals("Definition lists", h4.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("Definition_lists", a.getAttribute("name"));
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Below is a definition list, followed by six paragraphs.", p.asText().trim());
    HtmlDefinitionList dl = (HtmlDefinitionList) elementIterator.next();
    assertNotNull(dl);
    HtmlDefinitionTerm dt = (HtmlDefinitionTerm) elementIterator.next();
    assertNotNull(dt);
    assertEquals("Term 1.", dt.getFirstChild().asText().trim());
    HtmlDefinitionDescription dd = (HtmlDefinitionDescription) elementIterator.next();
    assertNotNull(dd);
    assertEquals("Description 1.", dd.getFirstChild().asText().trim());
    dt = (HtmlDefinitionTerm) elementIterator.next();
    assertNotNull(dt);
    assertEquals("Term 2.", dt.getFirstChild().asText().trim());
    dd = (HtmlDefinitionDescription) elementIterator.next();
    assertNotNull(dd);
    assertEquals("Description 2.", dd.getFirstChild().asText().trim());
    dl = (HtmlDefinitionList) elementIterator.next();
    assertNotNull(dl);
    dt = (HtmlDefinitionTerm) elementIterator.next();
    assertNotNull(dt);
    assertEquals("Term 21.", dt.getFirstChild().asText().trim());
    dd = (HtmlDefinitionDescription) elementIterator.next();
    assertNotNull(dd);
    assertEquals("Description 21.", dd.getFirstChild().asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 1 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 2 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 3 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 4 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 5 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 6 below list.", p.asText().trim());
    assertFalse(elementIterator.hasNext());
}
Also used : HtmlUnorderedList(com.gargoylesoftware.htmlunit.html.HtmlUnorderedList) HtmlHeading4(com.gargoylesoftware.htmlunit.html.HtmlHeading4) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlHeading2(com.gargoylesoftware.htmlunit.html.HtmlHeading2) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision) HtmlOrderedList(com.gargoylesoftware.htmlunit.html.HtmlOrderedList) HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlDefinitionList(com.gargoylesoftware.htmlunit.html.HtmlDefinitionList) HtmlParagraph(com.gargoylesoftware.htmlunit.html.HtmlParagraph) HtmlSection(com.gargoylesoftware.htmlunit.html.HtmlSection) HtmlDefinitionTerm(com.gargoylesoftware.htmlunit.html.HtmlDefinitionTerm) HtmlListItem(com.gargoylesoftware.htmlunit.html.HtmlListItem) HtmlDefinitionDescription(com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription)

Example 2 with HtmlDefinitionDescription

use of com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription in project stapler by jenkinsci.

the class BodyExpressionTest method testBodyExpression.

public void testBodyExpression() throws Exception {
    WebClient wc = new WebClient();
    HtmlPage page = wc.getPage(new URL(url, "/"));
    DomNodeList<DomElement> dts = page.getElementsByTagName("dt");
    assertEquals(1, dts.size());
    HtmlDefinitionTerm dt = (HtmlDefinitionTerm) dts.get(0);
    assertEquals("Timezone", dt.asNormalizedText());
    DomNodeList<DomElement> dds = page.getElementsByTagName("dd");
    assertEquals(1, dds.size());
    HtmlDefinitionDescription dd = (HtmlDefinitionDescription) dds.get(0);
    if (JavaSpecificationVersion.forCurrentJVM().isOlderThan(new VersionNumber("16"))) {
        // TODO JENKINS-68215 does not yet work on Java 16+
        assertNotNull(Float.parseFloat(dd.asNormalizedText()));
    }
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlDefinitionTerm(com.gargoylesoftware.htmlunit.html.HtmlDefinitionTerm) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) HtmlDefinitionDescription(com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription) VersionNumber(hudson.util.VersionNumber)

Example 3 with HtmlDefinitionDescription

use of com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription in project maven-doxia-sitetools by apache.

the class FaqVerifier method verify.

/**
 * {@inheritDoc}
 */
public void verify(String file) throws Exception {
    HtmlPage page = htmlPage(file);
    assertNotNull(page);
    HtmlElement element = page.getHtmlElementById("contentBox");
    assertNotNull(element);
    HtmlDivision division = (HtmlDivision) element;
    assertNotNull(division);
    Iterator<HtmlElement> elementIterator = division.getHtmlElementDescendants().iterator();
    // ----------------------------------------------------------------------
    // 
    // ----------------------------------------------------------------------
    HtmlSection section = (HtmlSection) elementIterator.next();
    HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
    assertEquals("Oft Asked Questions", h2.asText().trim());
    HtmlAnchor a = (HtmlAnchor) elementIterator.next();
    assertEquals(a.getAttribute("name"), "Oft_Asked_Questions");
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("top", a.getAttribute("name"));
    HtmlParagraph p = (HtmlParagraph) elementIterator.next();
    element = elementIterator.next();
    assertEquals("b", element.getTagName());
    assertEquals("Contributing", element.asText().trim());
    HtmlOrderedList ol = (HtmlOrderedList) elementIterator.next();
    assertEquals("One stupid question & a silly answer?", ol.getFirstElementChild().asText().trim());
    HtmlListItem li = (HtmlListItem) elementIterator.next();
    assertEquals("One stupid question & a silly answer?", li.getFirstElementChild().asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#stupid-question", a.getAttribute("href"));
    element = elementIterator.next();
    assertEquals("b", element.getTagName());
    assertEquals("stupid", element.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    element = elementIterator.next();
    assertEquals("b", element.getTagName());
    assertEquals("Using Maven", element.asText().trim());
    ol = (HtmlOrderedList) elementIterator.next();
    assertEquals("How do I disable a report on my site?", ol.getFirstElementChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("How do I disable a report on my site?", li.getFirstElementChild().asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#disable-reports", a.getAttribute("href"));
    section = (HtmlSection) elementIterator.next();
    h2 = (HtmlHeading2) elementIterator.next();
    assertEquals("Contributing", h2.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Contributing", a.getAttribute("name"));
    HtmlDefinitionList dl = (HtmlDefinitionList) elementIterator.next();
    HtmlDefinitionTerm dt = (HtmlDefinitionTerm) elementIterator.next();
    assertEquals("One stupid question & a silly answer?", dt.getFirstChild().asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("stupid-question", a.getAttribute("name"));
    element = elementIterator.next();
    assertEquals("b", element.getTagName());
    assertEquals("stupid", element.asText().trim());
    HtmlDefinitionDescription dd = (HtmlDefinitionDescription) elementIterator.next();
    p = (HtmlParagraph) elementIterator.next();
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#Using_Maven", a.getAttribute("href"));
    assertEquals("local link", a.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("./cdc.html", a.getAttribute("href"));
    assertEquals("source document", a.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("http://maven.apache.org/?l=a&m=b", a.getAttribute("href"));
    assertEquals("external link", a.asText().trim());
    element = elementIterator.next();
    assertEquals("i", element.getTagName());
    assertEquals("italic", element.asText().trim());
    element = elementIterator.next();
    assertEquals("b", element.getTagName());
    assertEquals("non-US-ASCII characters: àéèç", element.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertEquals("right", p.getAttribute("align"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#top", a.getAttribute("href"));
    assertEquals("[top]", a.asText().trim());
    section = (HtmlSection) elementIterator.next();
    h2 = (HtmlHeading2) elementIterator.next();
    assertEquals("Using Maven", h2.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Using_Maven", a.getAttribute("name"));
    dl = (HtmlDefinitionList) elementIterator.next();
    dt = (HtmlDefinitionTerm) elementIterator.next();
    assertEquals("How do I disable a report on my site?", dt.getFirstChild().asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("disable-reports", a.getAttribute("name"));
    dd = (HtmlDefinitionDescription) elementIterator.next();
    p = (HtmlParagraph) elementIterator.next();
    element = elementIterator.next();
    assertEquals("code", element.getTagName());
    assertEquals("<source></source>", element.asText().trim());
    HtmlDivision div = (HtmlDivision) elementIterator.next();
    assertEquals("source", div.getAttribute("class"));
    HtmlPreformattedText pre = (HtmlPreformattedText) elementIterator.next();
    assertEquals("<source>1.5</source>", pre.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertEquals("right", p.getAttribute("align"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#top", a.getAttribute("href"));
    assertEquals("[top]", a.asText().trim());
    assertFalse(elementIterator.hasNext());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlHeading2(com.gargoylesoftware.htmlunit.html.HtmlHeading2) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision) HtmlOrderedList(com.gargoylesoftware.htmlunit.html.HtmlOrderedList) HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlDefinitionList(com.gargoylesoftware.htmlunit.html.HtmlDefinitionList) HtmlParagraph(com.gargoylesoftware.htmlunit.html.HtmlParagraph) HtmlSection(com.gargoylesoftware.htmlunit.html.HtmlSection) HtmlDefinitionTerm(com.gargoylesoftware.htmlunit.html.HtmlDefinitionTerm) HtmlListItem(com.gargoylesoftware.htmlunit.html.HtmlListItem) HtmlDefinitionDescription(com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription) HtmlPreformattedText(com.gargoylesoftware.htmlunit.html.HtmlPreformattedText)

Aggregations

HtmlDefinitionDescription (com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription)3 HtmlDefinitionTerm (com.gargoylesoftware.htmlunit.html.HtmlDefinitionTerm)3 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)2 HtmlDefinitionList (com.gargoylesoftware.htmlunit.html.HtmlDefinitionList)2 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlHeading2 (com.gargoylesoftware.htmlunit.html.HtmlHeading2)2 HtmlListItem (com.gargoylesoftware.htmlunit.html.HtmlListItem)2 HtmlOrderedList (com.gargoylesoftware.htmlunit.html.HtmlOrderedList)2 HtmlParagraph (com.gargoylesoftware.htmlunit.html.HtmlParagraph)2 HtmlSection (com.gargoylesoftware.htmlunit.html.HtmlSection)2 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 HtmlHeading4 (com.gargoylesoftware.htmlunit.html.HtmlHeading4)1 HtmlPreformattedText (com.gargoylesoftware.htmlunit.html.HtmlPreformattedText)1 HtmlUnorderedList (com.gargoylesoftware.htmlunit.html.HtmlUnorderedList)1 VersionNumber (hudson.util.VersionNumber)1 URL (java.net.URL)1