Search in sources :

Example 6 with HtmlHeading2

use of com.gargoylesoftware.htmlunit.html.HtmlHeading2 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)

Example 7 with HtmlHeading2

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

the class MultipleBlockVerifier 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("section name", h2.asText().trim());
    HtmlAnchor a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("section_name", a.getAttribute("name"));
    // ----------------------------------------------------------------------
    // Paragraph
    // ----------------------------------------------------------------------
    HtmlParagraph p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("text", p.asText().trim());
    // ----------------------------------------------------------------------
    // Unordered list
    // ----------------------------------------------------------------------
    HtmlUnorderedList ul = (HtmlUnorderedList) elementIterator.next();
    assertNotNull(ul);
    HtmlListItem li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("list1", li.getFirstChild().asText().trim());
    // ----------------------------------------------------------------------
    // Paragraph
    // ----------------------------------------------------------------------
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("text2", p.asText().trim());
    // ----------------------------------------------------------------------
    // Unordered list
    // ----------------------------------------------------------------------
    ul = (HtmlUnorderedList) elementIterator.next();
    assertNotNull(ul);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("list1", li.getFirstChild().asText().trim());
    // ----------------------------------------------------------------------
    // Paragraph
    // ----------------------------------------------------------------------
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("text3", p.asText().trim());
    // ----------------------------------------------------------------------
    // Unordered list
    // ----------------------------------------------------------------------
    ul = (HtmlUnorderedList) elementIterator.next();
    assertNotNull(ul);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("list1", p.getFirstChild().asText().trim());
    assertFalse(elementIterator.hasNext());
}
Also used : HtmlUnorderedList(com.gargoylesoftware.htmlunit.html.HtmlUnorderedList) HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlHeading2(com.gargoylesoftware.htmlunit.html.HtmlHeading2) HtmlParagraph(com.gargoylesoftware.htmlunit.html.HtmlParagraph) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlSection(com.gargoylesoftware.htmlunit.html.HtmlSection) HtmlListItem(com.gargoylesoftware.htmlunit.html.HtmlListItem) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision)

Aggregations

HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)7 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)7 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)7 HtmlHeading2 (com.gargoylesoftware.htmlunit.html.HtmlHeading2)7 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)7 HtmlParagraph (com.gargoylesoftware.htmlunit.html.HtmlParagraph)7 HtmlSection (com.gargoylesoftware.htmlunit.html.HtmlSection)7 HtmlHeading3 (com.gargoylesoftware.htmlunit.html.HtmlHeading3)3 HtmlListItem (com.gargoylesoftware.htmlunit.html.HtmlListItem)3 HtmlPreformattedText (com.gargoylesoftware.htmlunit.html.HtmlPreformattedText)3 HtmlBold (com.gargoylesoftware.htmlunit.html.HtmlBold)2 HtmlDefinitionDescription (com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription)2 HtmlDefinitionList (com.gargoylesoftware.htmlunit.html.HtmlDefinitionList)2 HtmlDefinitionTerm (com.gargoylesoftware.htmlunit.html.HtmlDefinitionTerm)2 HtmlHeading4 (com.gargoylesoftware.htmlunit.html.HtmlHeading4)2 HtmlItalic (com.gargoylesoftware.htmlunit.html.HtmlItalic)2 HtmlOrderedList (com.gargoylesoftware.htmlunit.html.HtmlOrderedList)2 HtmlUnorderedList (com.gargoylesoftware.htmlunit.html.HtmlUnorderedList)2 CollectingAlertHandler (com.gargoylesoftware.htmlunit.CollectingAlertHandler)1 WebClient (com.gargoylesoftware.htmlunit.WebClient)1