Search in sources :

Example 1 with HtmlItalic

use of com.gargoylesoftware.htmlunit.html.HtmlItalic in project htmlunit by HtmlUnit.

the class GWT250Test method assertElementValue.

/**
 * Test value inside {@link HtmlDivision}, {@link HtmlInput} or {@link DomText}
 *
 * @param element the element to search in
 * @param expectedValue expected value of the value inside the cell
 */
private static void assertElementValue(final HtmlElement element, final String expectedValue) {
    DomNode child = element.getFirstChild();
    while (child != null && !(child instanceof DomElement) && (!(child instanceof DomText) || !((DomText) child).getData().equals(expectedValue))) {
        child = child.getNextSibling();
    }
    if (child instanceof HtmlDivision) {
        final HtmlDivision div = (HtmlDivision) child;
        DomNode firstChild = div.getFirstChild();
        while (firstChild != null && !(firstChild instanceof DomElement)) {
            firstChild = firstChild.getNextSibling();
        }
        if (firstChild instanceof HtmlBold || firstChild instanceof HtmlItalic) {
            firstChild = firstChild.getFirstChild();
        }
        if (firstChild instanceof DomText) {
            final DomText text = (DomText) firstChild;
            assertEquals(expectedValue, text.getData());
        } else {
            fail("Could not find '" + expectedValue + "'");
        }
    } else if (child instanceof HtmlInput) {
        final HtmlInput input = (HtmlInput) child;
        assertEquals(expectedValue, input.getValueAttribute());
    } else if (child instanceof DomText) {
        final DomText text = (DomText) child;
        assertEquals(expectedValue, text.getData());
    } else {
        fail("Could not find '" + expectedValue + "'");
    }
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) DomText(com.gargoylesoftware.htmlunit.html.DomText) HtmlItalic(com.gargoylesoftware.htmlunit.html.HtmlItalic) HtmlBold(com.gargoylesoftware.htmlunit.html.HtmlBold) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput)

Example 2 with HtmlItalic

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

the class AptVerifier 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();
    assertNotNull(h2);
    assertEquals("Links", h2.asText().trim());
    HtmlAnchor a = (HtmlAnchor) elementIterator.next();
    assertEquals("Links", a.getAttribute("name"));
    HtmlParagraph p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    // Expected log: [APT Parser] Ambiguous link: 'cdc.html'. If this is a local link, prepend "./"!
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Anchor", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("cdc.html", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#Anchor", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#Anchor", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Anchor_with_space", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#Anchor_with_space", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("http://maven.apache.org/", a.getAttribute("href"));
    assertEquals("externalLink", a.getAttribute("class"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("http://maven.apache.org/", a.getAttribute("href"));
    assertEquals("externalLink", a.getAttribute("class"));
    // Expected log: [APT Parser] Ambiguous link: 'cdc.html'. If this is a local link, prepend "./"!
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("./cdc.html", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#cdc.html", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("/index.html", a.getAttribute("href"));
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h2 = (HtmlHeading2) elementIterator.next();
    assertNotNull(h2);
    // Note: htmlunit strips the white space, actual result is ok
    assertEquals("Section formatting: italic bold mono", h2.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Section_formatting:_italic_bold_mono", a.getAttribute("name"));
    HtmlItalic italic = (HtmlItalic) elementIterator.next();
    assertEquals("i", italic.getTagName());
    assertEquals("italic", italic.asText().trim());
    HtmlBold bold = (HtmlBold) elementIterator.next();
    assertEquals("b", bold.getTagName());
    assertEquals("bold", bold.asText().trim());
    HtmlCode code = (HtmlCode) elementIterator.next();
    assertEquals("code", code.getTagName());
    assertEquals("mono", code.asText().trim());
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    HtmlHeading3 h3 = (HtmlHeading3) elementIterator.next();
    assertNotNull(h3);
    // Note: htmlunit strips the white space, actual result is ok
    assertEquals("SubSection formatting: italic bold mono", h3.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("SubSection_formatting:_italic_bold_mono", a.getAttribute("name"));
    italic = (HtmlItalic) elementIterator.next();
    assertEquals("i", italic.getTagName());
    assertEquals("italic", italic.asText().trim());
    bold = (HtmlBold) elementIterator.next();
    assertEquals("b", bold.getTagName());
    assertEquals("bold", bold.asText().trim());
    code = (HtmlCode) elementIterator.next();
    assertEquals("code", code.getTagName());
    assertEquals("mono", code.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    italic = (HtmlItalic) elementIterator.next();
    assertEquals("i", italic.getTagName());
    assertEquals("italic", italic.asText().trim());
    bold = (HtmlBold) elementIterator.next();
    assertEquals("b", bold.getTagName());
    assertEquals("bold", bold.asText().trim());
    code = (HtmlCode) elementIterator.next();
    assertEquals("code", code.getTagName());
    assertEquals("mono", code.asText().trim());
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h2 = (HtmlHeading2) elementIterator.next();
    assertNotNull(h2);
    assertEquals("No Default Anchor in Section Title with Explicit Anchor", h2.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("No_Default_Anchor_in_Section_Title_with_Explicit_Anchor", a.getAttribute("name"));
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
}
Also used : HtmlCode(com.gargoylesoftware.htmlunit.html.HtmlCode) HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlHeading3(com.gargoylesoftware.htmlunit.html.HtmlHeading3) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlHeading2(com.gargoylesoftware.htmlunit.html.HtmlHeading2) HtmlParagraph(com.gargoylesoftware.htmlunit.html.HtmlParagraph) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlItalic(com.gargoylesoftware.htmlunit.html.HtmlItalic) HtmlSection(com.gargoylesoftware.htmlunit.html.HtmlSection) HtmlBold(com.gargoylesoftware.htmlunit.html.HtmlBold) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision)

Example 3 with HtmlItalic

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

the class AttributesVerifier 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();
    assertNotNull(h2);
    assertEquals("section", h2.asText().trim());
    HtmlAnchor a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("section", a.getAttribute("name"));
    HtmlParagraph p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("ID", p.getAttribute("id"));
    assertEquals("CLASS", p.getAttribute("class"));
    assertEquals("TITLE", p.getAttribute("title"));
    assertEquals("STYLE", p.getAttribute("style"));
    assertEquals("LANG", p.getAttribute("lang"));
    HtmlImage img = (HtmlImage) elementIterator.next();
    assertNotNull(img);
    assertEquals("project.png", img.getAttribute("src"));
    assertEquals("150", img.getAttribute("width"));
    assertEquals("93", img.getAttribute("height"));
    assertEquals("border: 1px solid silver", img.getAttribute("style"));
    assertEquals("Project", img.getAttribute("alt"));
    // test object identity to distinguish the case ATTRIBUTE_VALUE_EMPTY
    assertSame(img.getAttribute("dummy"), HtmlElement.ATTRIBUTE_NOT_DEFINED);
    HtmlTable table = (HtmlTable) elementIterator.next();
    assertEquals("1", table.getAttribute("border"));
    assertEquals("none", table.getAttribute("class"));
    element = elementIterator.next();
    // this is a htmlunit bug
    assertEquals("tbody", element.getTagName());
    HtmlTableRow tr = (HtmlTableRow) elementIterator.next();
    HtmlTableHeaderCell th = (HtmlTableHeaderCell) elementIterator.next();
    th = (HtmlTableHeaderCell) elementIterator.next();
    assertEquals("center", th.getAttribute("align"));
    assertEquals("2", th.getAttribute("colspan"));
    assertEquals("50%", th.getAttribute("width"));
    tr = (HtmlTableRow) elementIterator.next();
    th = (HtmlTableHeaderCell) elementIterator.next();
    assertEquals("2", th.getAttribute("rowspan"));
    assertEquals("middle", th.getAttribute("valign"));
    HtmlTableDataCell td = (HtmlTableDataCell) elementIterator.next();
    td = (HtmlTableDataCell) elementIterator.next();
    tr = (HtmlTableRow) elementIterator.next();
    td = (HtmlTableDataCell) elementIterator.next();
    td = (HtmlTableDataCell) elementIterator.next();
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    HtmlUnderlined u = (HtmlUnderlined) elementIterator.next();
    assertEquals("u", u.getTagName());
    HtmlS s = (HtmlS) elementIterator.next();
    assertEquals("s", s.getTagName());
    HtmlSubscript sub = (HtmlSubscript) elementIterator.next();
    assertEquals("sub", sub.getTagName());
    HtmlSuperscript sup = (HtmlSuperscript) elementIterator.next();
    assertEquals("sup", sup.getTagName());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    HtmlBold b = (HtmlBold) elementIterator.next();
    assertEquals("b", b.getTagName());
    HtmlItalic i = (HtmlItalic) elementIterator.next();
    assertEquals("i", i.getTagName());
    i = (HtmlItalic) elementIterator.next();
    assertEquals("i", i.getTagName());
    b = (HtmlBold) elementIterator.next();
    assertEquals("b", b.getTagName());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("color: red; margin-left: 20px", p.getAttribute("style"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Anchor", a.getAttribute("name"));
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#Anchor", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#Anchor", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("http://maven.apache.org/", a.getAttribute("href"));
    assertEquals("externalLink", a.getAttribute("class"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("./cdc.html", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("cdc.html", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("cdc.pdf", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("./cdc.txt", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("/index.html", a.getAttribute("href"));
    HtmlDivision div = (HtmlDivision) elementIterator.next();
    assertEquals("source", div.getAttribute("class"));
    HtmlPreformattedText pre = (HtmlPreformattedText) elementIterator.next();
    assertEquals("pretty", pre.getAttribute("class"));
    div = (HtmlDivision) elementIterator.next();
    assertEquals("source", div.getAttribute("class"));
    assertEquals("", div.getAttribute("id"));
    pre = (HtmlPreformattedText) elementIterator.next();
    assertEquals("pretty", pre.getAttribute("id"));
    section = (HtmlSection) elementIterator.next();
    h2 = (HtmlHeading2) elementIterator.next();
    assertEquals("Section without id", h2.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Section_without_id", a.getAttribute("name"));
    section = (HtmlSection) elementIterator.next();
    HtmlHeading3 h3 = (HtmlHeading3) elementIterator.next();
    assertEquals("Subsection without id", h3.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Subsection_without_id", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("section-id", a.getAttribute("name"));
    section = (HtmlSection) elementIterator.next();
    h2 = (HtmlHeading2) elementIterator.next();
    assertEquals("Section with id", h2.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Section_with_id", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("subsection-id", a.getAttribute("name"));
    section = (HtmlSection) elementIterator.next();
    h3 = (HtmlHeading3) elementIterator.next();
    assertEquals("Subsection with id", h3.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Subsection_with_id", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("foo", a.getAttribute("name"));
    section = (HtmlSection) elementIterator.next();
    assertEquals("bar", section.getAttribute("class"));
    assertEquals("foo", section.getAttribute("id"));
    h2 = (HtmlHeading2) elementIterator.next();
    assertEquals("Section name", h2.asText().trim());
    assertEquals("", h2.getAttribute("class"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Section_name", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("subfoo", a.getAttribute("name"));
    section = (HtmlSection) elementIterator.next();
    assertEquals("subbar", section.getAttribute("class"));
    assertEquals("subfoo", section.getAttribute("id"));
    h3 = (HtmlHeading3) elementIterator.next();
    assertEquals("Subsection name", h3.asText().trim());
    assertEquals("", h3.getAttribute("class"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Subsection_name", a.getAttribute("name"));
    assertFalse(elementIterator.hasNext());
}
Also used : HtmlImage(com.gargoylesoftware.htmlunit.html.HtmlImage) HtmlTableRow(com.gargoylesoftware.htmlunit.html.HtmlTableRow) HtmlSuperscript(com.gargoylesoftware.htmlunit.html.HtmlSuperscript) HtmlHeading3(com.gargoylesoftware.htmlunit.html.HtmlHeading3) HtmlTable(com.gargoylesoftware.htmlunit.html.HtmlTable) HtmlS(com.gargoylesoftware.htmlunit.html.HtmlS) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlHeading2(com.gargoylesoftware.htmlunit.html.HtmlHeading2) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlTableDataCell(com.gargoylesoftware.htmlunit.html.HtmlTableDataCell) HtmlBold(com.gargoylesoftware.htmlunit.html.HtmlBold) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision) HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlParagraph(com.gargoylesoftware.htmlunit.html.HtmlParagraph) HtmlSubscript(com.gargoylesoftware.htmlunit.html.HtmlSubscript) HtmlItalic(com.gargoylesoftware.htmlunit.html.HtmlItalic) HtmlSection(com.gargoylesoftware.htmlunit.html.HtmlSection) HtmlTableHeaderCell(com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell) HtmlUnderlined(com.gargoylesoftware.htmlunit.html.HtmlUnderlined) HtmlPreformattedText(com.gargoylesoftware.htmlunit.html.HtmlPreformattedText)

Aggregations

HtmlBold (com.gargoylesoftware.htmlunit.html.HtmlBold)3 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)3 HtmlItalic (com.gargoylesoftware.htmlunit.html.HtmlItalic)3 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlHeading2 (com.gargoylesoftware.htmlunit.html.HtmlHeading2)2 HtmlHeading3 (com.gargoylesoftware.htmlunit.html.HtmlHeading3)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 HtmlParagraph (com.gargoylesoftware.htmlunit.html.HtmlParagraph)2 HtmlSection (com.gargoylesoftware.htmlunit.html.HtmlSection)2 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)1 DomText (com.gargoylesoftware.htmlunit.html.DomText)1 HtmlCode (com.gargoylesoftware.htmlunit.html.HtmlCode)1 HtmlImage (com.gargoylesoftware.htmlunit.html.HtmlImage)1 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)1 HtmlPreformattedText (com.gargoylesoftware.htmlunit.html.HtmlPreformattedText)1 HtmlS (com.gargoylesoftware.htmlunit.html.HtmlS)1 HtmlSubscript (com.gargoylesoftware.htmlunit.html.HtmlSubscript)1 HtmlSuperscript (com.gargoylesoftware.htmlunit.html.HtmlSuperscript)1