Search in sources :

Example 1 with HtmlTableHeaderCell

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

Example 2 with HtmlTableHeaderCell

use of com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell in project faces by jakartaee.

the class URLClient method dtableRenderEncodeTableHeaderFooterTest.

// END dtableRenderEncodeColGrpTest
/**
 * @testName: dtableRenderEncodeTableHeaderFooterTest
 * @assertion_ids: PENDING
 * @test_Strategy: Validate the following: Data1: - thead with single nested
 *                 tr/th element combination - th element has scope attribute
 *                 value of colgroup - th element has colspan of 3 as 3
 *                 columns are defined - th element has no class attribute
 *                 rendered - tfoot with single nested tr/td element
 *                 combination - td element has no scope attribute rendered -
 *                 td element has colspan of 3 as 3 columns are defined - td
 *                 element has no class attribute rendered Data2: - the same
 *                 as above except the class attribute value is validated on
 *                 the rendered th and td elements as headerClass and
 *                 footerClass are defined for this table in the JSP
 *
 * @since 1.2
 */
public void dtableRenderEncodeTableHeaderFooterTest() throws Fault {
    StringBuilder messages = new StringBuilder(128);
    Formatter formatter = new Formatter(messages);
    List<HtmlPage> pages = new ArrayList<HtmlPage>();
    pages.add(getPage(CONTEXT_ROOT + "/faces/encodetestTableHeaderFooter.xhtml"));
    pages.add(getPage(CONTEXT_ROOT + "/faces/encodetestTableHeaderFooter_facelet.xhtml"));
    for (HtmlPage page : pages) {
        HtmlTable data1 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "data1");
        if (!validateExistence("data1", "table", data1, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // One table header should be available with a cell
        // spanning all three specified columns
        HtmlTableHeader data1Header = data1.getHeader();
        if (data1Header == null) {
            formatter.format("Header not rendered for table containing " + "ID 'data1' when header facet was specified. %n");
        } else {
            // should find a single row with a colspan of 3.
            if (data1Header.getRows().size() != 1) {
                formatter.format("Expected a single table header row for " + "table containing ID 'data1', but found '%s' %n", data1Header.getRows().size());
            } else {
                List headerRows = data1Header.getRows();
                HtmlTableRow row = (HtmlTableRow) headerRows.get(0);
                HtmlTableHeaderCell cell = (HtmlTableHeaderCell) row.getCell(0);
                if (cell.getColumnSpan() != 3) {
                    formatter.format("Expected table header cell for " + "table containing ID 'data1' to have a " + "colspan of 3 as three columns was " + "specified.  Colspan received '%s' %n.", cell.getColumnSpan());
                } else {
                    if (!"Header Text For Data1".equals(cell.asText())) {
                        formatter.format("Expected table header cell " + "for table containing ID 'data1' to " + "contain 'Header Text For Data1', " + "received: '%s'. %n", cell.asText());
                    }
                }
                // validate scope attribute for the th element of the header
                if (!"colgroup".equals(cell.getScopeAttribute())) {
                    formatter.format("Expected the scope attribute of " + "the 'th' element to be 'colgroup', but " + "found '%s' %n", cell.getScopeAttribute());
                }
                // validate no class attribute was rendered
                if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("class"))) {
                    formatter.format("Expected no class attribute to be " + "rendered on the 'th' element since no " + "headerClass attribute was defined in the JSP");
                }
            }
        }
        // One table footer should be available with a cell
        // spanning all three specified columns
        HtmlTableFooter data1Footer = data1.getFooter();
        if (data1Footer == null) {
            formatter.format("Footer not rendered for table containing " + "ID 'data1' when footer facet was specified. %n");
        } else {
            // should find a single row with a colspan of 3.
            if (data1Footer.getRows().size() != 1) {
                formatter.format("Expected a single table footer row for " + "table containing ID 'data1', but found '%s' %n", data1Footer.getRows().size());
            } else {
                List footerRows = data1Footer.getRows();
                HtmlTableRow row = (HtmlTableRow) footerRows.get(0);
                HtmlTableCell cell = row.getCell(0);
                if (cell.getColumnSpan() != 3) {
                    formatter.format("Expected table footer cell for " + "table containing ID 'data1' to have a " + "colspan of 3 as three columns was " + "specified. Colspan received '%s' %n.", cell.getColumnSpan());
                } else {
                    if (!"Footer Text For Data1".equals(cell.asText())) {
                        formatter.format("Expected table footer cell for " + "table containing ID 'data1' to " + "contain 'Footer Text For Data1', " + "received: '%s'. %n", cell.asText());
                    }
                }
                if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("scope"))) {
                    formatter.format("Expected no scope attribute to " + "be rendered on the table footer, but " + "the attribute was found.");
                }
                // validate no class attribute was rendered
                if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("class"))) {
                    formatter.format("Expected no class attribute to " + "be rendered for the footer since no " + "footerClass attribute was defined in the JSP");
                }
            }
        }
        validateTableBodyRows(data1, "data1", null, null, formatter);
        // ---------------------------------------------------------- Data 2
        HtmlTable data2 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "data2");
        if (!validateExistence("data2", "table", data2, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // One table header should be available with a cell
        // spanning all three specified columns
        HtmlTableHeader data2Header = data2.getHeader();
        if (data2Header == null) {
            formatter.format("Header not rendered for table containing " + "ID 'data2' when header facet was specified. %n");
        } else {
            // should find a single row with a colspan of 3.
            if (data2Header.getRows().size() != 1) {
                formatter.format("Expected a single table header row " + "for table containing ID 'data2', but found '%s'%n", data2Header.getRows().size());
            } else {
                List headerRows = data2Header.getRows();
                HtmlTableRow row = (HtmlTableRow) headerRows.get(0);
                HtmlTableHeaderCell cell = (HtmlTableHeaderCell) row.getCell(0);
                if (cell.getColumnSpan() != 3) {
                    formatter.format("Expected table header cell for " + "table containing ID 'data2' to have a " + "colspan of 3 as three columns was " + "specified. Colspan received '%s' %n.", cell.getColumnSpan());
                } else {
                    if (!"Header Text For Data2".equals(cell.asText())) {
                        formatter.format("Expected table header cell for " + "table containing ID 'data2' to contain " + "'Header Text For Data2', " + "received: '%s'.%n", cell.asText());
                    }
                }
                // validate scope attribute for the th element of the header
                if (!"colgroup".equals(cell.getScopeAttribute())) {
                    formatter.format("Expected the scope attribute of " + "the 'th' element to be 'colgroup', but " + "found '%s' %n", cell.getScopeAttribute());
                }
                // validate class attribute was rendered
                if (!"sansserif".equals(cell.getAttribute("class"))) {
                    formatter.format("Expected the class attribute " + "of the 'th' element to be 'sansserif', " + "but found '%s' %n", cell.getAttribute("class"));
                }
            }
        }
        // One table footer should be available with a cell
        // spanning all three specified columns
        HtmlTableFooter data2Footer = data2.getFooter();
        if (data2Footer == null) {
            formatter.format("Footer not rendered for table containing " + "ID 'data2' when footer facet was specified. %n");
        } else {
            // should find a single row with a colspan of 3.
            if (data2Footer.getRows().size() != 1) {
                formatter.format("Expected a single table footer row " + "for table containing ID 'data2', but " + "found '%s' %n", data2Footer.getRows().size());
            } else {
                List footerRows = data2Footer.getRows();
                HtmlTableRow row = (HtmlTableRow) footerRows.get(0);
                HtmlTableCell cell = row.getCell(0);
                if (cell.getColumnSpan() != 3) {
                    formatter.format("Expected table footer cell for " + "table containing ID 'data2' to have a " + "colspan of 3 as three columns was " + "specified. Colspan received '%s' %n.", cell.getColumnSpan());
                } else {
                    if (!"Footer Text For Data2".equals(cell.asText())) {
                        formatter.format("Expected table footer cell for " + "table containing ID 'data2' to contain " + "Footer Text For Data2', received: " + "'%s'. %n", cell.asText());
                    }
                }
                if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("scope"))) {
                    formatter.format("Expected no scope attribute to be " + "rendered on the table footer, but the " + "attribute was found.");
                }
                // validate class attribute was rendered
                if (!"sansserif".equals(cell.getAttribute("class"))) {
                    formatter.format("Expected the class attribute of " + "the 'td' element of the footer to be " + "'sansserif', but found '%s' %n", cell.getAttribute("class"));
                }
            }
        }
        validateTableBodyRows(data2, "data2", null, null, formatter);
        handleTestStatus(messages);
    }
}
Also used : HtmlTableRow(com.gargoylesoftware.htmlunit.html.HtmlTableRow) HtmlTable(com.gargoylesoftware.htmlunit.html.HtmlTable) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Formatter(java.util.Formatter) HtmlTableFooter(com.gargoylesoftware.htmlunit.html.HtmlTableFooter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HtmlTableHeaderCell(com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell) HtmlTableCell(com.gargoylesoftware.htmlunit.html.HtmlTableCell) HtmlTableHeader(com.gargoylesoftware.htmlunit.html.HtmlTableHeader)

Example 3 with HtmlTableHeaderCell

use of com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell in project faces by jakartaee.

the class URLClient method gridRenderEncodeTableHeaderFooterTest.

// END gridRenderEncodeCaptionTest
/**
 * @testName: gridRenderEncodeTableHeaderFooterTest
 * @assertion_ids: PENDING
 * @test_Strategy: Validate the following: Grid1: - thead with single nested
 *                 tr/th element combination - th element has scope attribute
 *                 value of colgroup - th element has colspan of 3 as 3
 *                 columns are defined - th element has no class attribute
 *                 rendered - tfoot with single nested tr/td element
 *                 combination - td element has no scope attribute rendered -
 *                 td element has colspan of 3 as 3 columns are defined - td
 *                 element has no class attribute rendered Grid2: - the same
 *                 as above except the class attribute value is validated on
 *                 the rendered th and td elements as headerClass and
 *                 footerClass are defined for this table in the JSP
 *
 * @since 1.2
 */
public void gridRenderEncodeTableHeaderFooterTest() throws Fault {
    StringBuilder messages = new StringBuilder(128);
    Formatter formatter = new Formatter(messages);
    List<HtmlPage> pages = new ArrayList<HtmlPage>();
    pages.add(getPage(CONTEXT_ROOT + "/faces/encodetestTableHeaderFooter.xhtml"));
    pages.add(getPage(CONTEXT_ROOT + "/faces/encodetestTableHeaderFooter_facelet.xhtml"));
    for (HtmlPage page : pages) {
        HtmlTable grid1 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "grid1");
        if (!validateExistence("grid1", "table", grid1, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // One table header should be available with a cell
        // spanning all three specified columns
        HtmlTableHeader grid1Header = grid1.getHeader();
        if (grid1Header == null) {
            formatter.format("Header not rendered for table containing ID 'grid1'" + " when header facet was specified.%n");
        } else {
            // should find a single row with a colspan of 3.
            if (grid1Header.getRows().size() != 1) {
                formatter.format("Expected a single table header row for table " + "containing ID 'grid1', but found '%s'%n", grid1Header.getRows().size());
            } else {
                List headerRows = grid1Header.getRows();
                HtmlTableRow row = (HtmlTableRow) headerRows.get(0);
                HtmlTableHeaderCell cell = (HtmlTableHeaderCell) row.getCell(0);
                if (cell.getColumnSpan() != 3) {
                    formatter.format("Expected table header cell for " + "table containing ID 'grid1' to have a " + "colspan of 3 as three columns" + " was specified.  Colspan received '%s'%n.", cell.getColumnSpan());
                } else {
                    if (!"Header Text For Grid1".equals(cell.asText())) {
                        formatter.format("Expected table header cell for " + "table containing ID 'grid1' to contain " + "'Header Text For Grid1', " + "received: '%s'.%n", cell.asText());
                    }
                }
                // validate scope attribute for the th element of the header
                if (!"colgroup".equals(cell.getScopeAttribute())) {
                    formatter.format("Expected the scope attribute of " + "the 'th' element to be 'colgroup', but " + "found '%s'%n", cell.getScopeAttribute());
                }
                // validate no class attribute was rendered
                if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("class"))) {
                    formatter.format("Expected no class attribute to be " + "rendered on the 'th' element since no " + "headerClass attribute was defined in the JSP");
                }
            }
        }
        // One table footer should be available with a cell
        // spanning all three specified columns
        HtmlTableFooter grid1Footer = grid1.getFooter();
        if (grid1Footer == null) {
            formatter.format("Footer not rendered for table containing " + "ID 'grid1' when footer facet was specified.%n");
        } else {
            // should find a single row with a colspan of 3.
            if (grid1Footer.getRows().size() != 1) {
                formatter.format("Expected a single table footer row for " + "table containing ID 'grid1', but found '%s'%n", grid1Footer.getRows().size());
            } else {
                List footerRows = grid1Footer.getRows();
                HtmlTableRow row = (HtmlTableRow) footerRows.get(0);
                HtmlTableCell cell = row.getCell(0);
                if (cell.getColumnSpan() != 3) {
                    formatter.format("Expected table footer cell for " + "table containing  ID 'grid1' to have a " + "colspan of 3 as three columns" + " was specified.  Colspan received '%s'%n.", cell.getColumnSpan());
                } else {
                    if (!"Footer Text For Grid1".equals(cell.asText())) {
                        formatter.format("Expected table footer cell for " + "table containing ID 'grid1' to contain " + "'Footer Text For Grid1', " + "received: '%s'.%n", cell.asText());
                    }
                }
                if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("scope"))) {
                    formatter.format("Expected no scope attribute to be " + "rendered on the table footer, but the " + "attribute was found.");
                }
                // validate no class attribute was rendered
                if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("class"))) {
                    formatter.format("Expected no class attribute to be " + "rendered for the footer since no footerClass" + " attribute was defined in the JSP");
                }
            }
        }
        validateTableBodyRows(grid1, "grid1", 1, 3, null, null, formatter);
        // ----------------------------------------------------------- Grid2
        HtmlTable grid2 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "grid2");
        if (!validateExistence("grid2", "table", grid2, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // One table header should be available with a cell
        // spanning all three specified columns
        HtmlTableHeader grid2Header = grid2.getHeader();
        if (grid2Header == null) {
            formatter.format("Header not rendered for table containing " + "ID 'grid2' when header facet was specified.%n");
        } else {
            // should find a single row with a colspan of 3.
            if (grid2Header.getRows().size() != 1) {
                formatter.format("Expected a single table header row " + "for table containing ID 'grid2', but found '%s'%n", grid2Header.getRows().size());
            } else {
                List headerRows = grid2Header.getRows();
                HtmlTableRow row = (HtmlTableRow) headerRows.get(0);
                HtmlTableHeaderCell cell = (HtmlTableHeaderCell) row.getCell(0);
                if (cell.getColumnSpan() != 3) {
                    formatter.format("Expected table header cell for " + "table containing ID 'grid2' to have a " + "colspan of 3 as three columns" + " was specified.  Colspan received '%s'%n.", cell.getColumnSpan());
                } else {
                    if (!"Header Text For Grid2".equals(cell.asText())) {
                        formatter.format("Expected table header cell for " + "table containing ID 'grid2' to contain " + "'Header Text For Grid2', " + "received: '%s'.%n", cell.asText());
                    }
                }
                // validate scope attribute for the th element of the header
                if (!"colgroup".equals(cell.getScopeAttribute())) {
                    formatter.format("Expected the scope attribute of " + "the 'th' element to be 'colgroup', but " + "found '%s'%n", cell.getScopeAttribute());
                }
                // validate class attribute was rendered
                if (!"sansserif".equals(cell.getAttribute("class"))) {
                    formatter.format("Expected the class attribute of " + "the 'th' element to be 'sansserif', but " + "found '%s'%n", cell.getAttribute("class"));
                }
            }
        }
        // One table footer should be available with a cell
        // spanning all three specified columns
        HtmlTableFooter grid2Footer = grid2.getFooter();
        if (grid2Footer == null) {
            formatter.format("Footer not rendered for table containing " + "ID 'grid2' when footer facet was specified.%n");
        } else {
            // should find a single row with a colspan of 3.
            if (grid2Footer.getRows().size() != 1) {
                formatter.format("Expected a single table footer row " + "for table containing ID 'grid2', but found '%s'%n", grid2Footer.getRows().size());
            } else {
                List footerRows = grid2Footer.getRows();
                HtmlTableRow row = (HtmlTableRow) footerRows.get(0);
                HtmlTableCell cell = row.getCell(0);
                if (cell.getColumnSpan() != 3) {
                    formatter.format("Expected table footer cell for " + "table containing ID 'grid2' to have a " + "colspan of 3 as three columns" + " was specified.  Colspan received '%s'%n.", cell.getColumnSpan());
                } else {
                    if (!"Footer Text For Grid2".equals(cell.asText())) {
                        formatter.format("Expected table footer cell for " + "table containing ID 'grid2' to contain " + "'Footer Text For Grid2', " + "received: '%s'.%n", cell.asText());
                    }
                }
                if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("scope"))) {
                    formatter.format("Expected no scope attribute to " + "be rendered on the table footer, but the " + "attribute was found.");
                }
                // validate class attribute was rendered
                if (!"sansserif".equals(cell.getAttribute("class"))) {
                    formatter.format("Expected the class attribute of " + "the 'td' element of the footer to be " + "'sansserif', but found '%s'%n", cell.getAttribute("class"));
                }
            }
        }
        validateTableBodyRows(grid2, "grid2", 1, 3, null, null, formatter);
        handleTestStatus(messages);
    }
}
Also used : HtmlTableRow(com.gargoylesoftware.htmlunit.html.HtmlTableRow) HtmlTable(com.gargoylesoftware.htmlunit.html.HtmlTable) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Formatter(java.util.Formatter) HtmlTableFooter(com.gargoylesoftware.htmlunit.html.HtmlTableFooter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HtmlTableHeaderCell(com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell) HtmlTableCell(com.gargoylesoftware.htmlunit.html.HtmlTableCell) HtmlTableHeader(com.gargoylesoftware.htmlunit.html.HtmlTableHeader)

Example 4 with HtmlTableHeaderCell

use of com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell in project faces by jakartaee.

the class URLClient method dtableRenderEncodeColumnHeaderFooterTest.

// END dtableRenderEncodeTableHeaderFooterTest
/**
 * @testName: dtableRenderEncodeColumnHeaderFooterTest
 * @assertion_ids: PENDING
 * @test_Strategy: Validate the following: Data1: - thead with three nested
 *                 tr/th element combinations - each th element has scope
 *                 attribute value of col - each th element has no class
 *                 attribute rendered - tfoot with three nested tr/td element
 *                 combinations - each td element has no scope attribute
 *                 rendered - each td element has no class attribute rendered
 *                 Data2: - the same as above except the class attribute value
 *                 is validated on the rendered th and td elements as
 *                 headerClass and footerClass are defined for this table in
 *                 the JSP Data3: - the same as Data1, except headerClass and
 *                 footerClass are defined on the table as well as two of the
 *                 columns. Validate that the class specified on the column
 *                 level overrides the table level definition
 *
 * @since 1.2
 */
public void dtableRenderEncodeColumnHeaderFooterTest() throws Fault {
    StringBuilder messages = new StringBuilder(128);
    Formatter formatter = new Formatter(messages);
    List<HtmlPage> pages = new ArrayList<HtmlPage>();
    pages.add(getPage(CONTEXT_ROOT + "/faces/encodetestColumnHeaderFooter.xhtml"));
    pages.add(getPage(CONTEXT_ROOT + "/faces/encodetestColumnHeaderFooter_facelet.xhtml"));
    for (HtmlPage page : pages) {
        HtmlTable data1 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "data1");
        if (!validateExistence("data1", "table", data1, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // There should be one thead containing one tr and three th's
        HtmlTableHeader data1Header = data1.getHeader();
        if (data1Header == null) {
            formatter.format("Header not rendered for table containing " + "ID 'data1' when header facet was specified on the " + "specified columns %n");
        } else {
            // should find 1 header rows
            if (data1Header.getRows().size() != 1) {
                formatter.format("Expected a single table header row for " + "table containing ID 'data1', but found '%s' %n", data1Header.getRows().size());
            } else {
                String[] headerCellValues = new String[] { "Name Header", "", "Age Header" };
                HtmlTableRow row = (HtmlTableRow) data1Header.getRows().get(0);
                List headerCells = row.getCells();
                for (int i = 0, size = headerCells.size(); i < size; i++) {
                    HtmlTableHeaderCell cell = (HtmlTableHeaderCell) row.getCell(i);
                    if (!headerCellValues[i].equals(cell.asText())) {
                        formatter.format("Expected table header cell(%s) " + "for table containing ID 'data1' to " + "contain '%s', received: '%s'. %n", i, headerCellValues[i], cell.asText());
                    }
                    // column header as expected
                    if (!"col".equals(cell.getScopeAttribute())) {
                        formatter.format("Expected table header cell(%s) " + "for table containing ID 'data1' to have " + "a scope attribute value of 'col', " + "but found '%s' %n", i, cell.getScopeAttribute());
                    }
                }
            }
        }
        // There should be one footer containing one row and three td's
        HtmlTableFooter data1Footer = data1.getFooter();
        if (data1Footer == null) {
            formatter.format("Footers not rendered for table containing " + "ID 'data1' when footer facet was specified on the " + "specified columns %n");
        } else {
            // should find 1 header rows
            if (data1Footer.getRows().size() != 1) {
                formatter.format("Expected a single table footer row for " + "table containing ID 'data1', but found '%s' %n", data1Footer.getRows().size());
            } else {
                String[] footerCellValues = new String[] { "", "Gender Footer", "Age Footer" };
                HtmlTableRow row = (HtmlTableRow) data1Footer.getRows().get(0);
                List headerCells = row.getCells();
                for (int i = 0, size = headerCells.size(); i < size; i++) {
                    HtmlTableCell cell = row.getCell(i);
                    if (!footerCellValues[i].equals(cell.asText())) {
                        formatter.format("Expected table footer cell(%s) " + "for table containing ID 'data1' to " + "contain '%s', received: '%s'. %n", i, footerCellValues[i], cell.asText());
                    }
                    // validate no scope attribute is rendered
                    if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("scope"))) {
                        formatter.format("Expected no scope attribute to " + "be rendered for footer cell(%s) in table" + " containing ID 'data1' %n", i);
                    }
                }
            }
        }
        validateTableBodyRows(data1, "data1", null, null, formatter);
        // ---------------------------------------------------------- Data 2
        // this table has headerClass and footerClass defined on the
        // dataTable tag. This should result in class being rendered
        // for each header and footer row.
        HtmlTable data2 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "data2");
        if (!validateExistence("data2", "table", data2, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // There should be one thead containing one tr and three th's
        HtmlTableHeader data2Header = data2.getHeader();
        if (data2Header == null) {
            formatter.format("Header not rendered for table containing " + "ID 'data2' when header facet was specified on the " + "specified columns %n");
        } else {
            // should find 1 header rows
            if (data2Header.getRows().size() != 1) {
                formatter.format("Expected a single table header row " + "for table containing ID 'data2', but found '%s'%n", data2Header.getRows().size());
            } else {
                String[] headerCellValues = new String[] { "Name Header", "", "Age Header" };
                HtmlTableRow row = (HtmlTableRow) data2Header.getRows().get(0);
                List headerCells = row.getCells();
                for (int i = 0, size = headerCells.size(); i < size; i++) {
                    HtmlTableHeaderCell cell = (HtmlTableHeaderCell) row.getCell(i);
                    if (!headerCellValues[i].equals(cell.asText())) {
                        formatter.format("Expected table header cell(%s) " + "for table containing ID 'data2' to " + "contain '%s', received: '%s'. %n", i, headerCellValues[i], cell.asText());
                    }
                    // column header as expected
                    if (!"col".equals(cell.getScopeAttribute())) {
                        formatter.format("Expected table header cell(%s) " + "for table containing ID 'data2' to have " + "a scope attribute value of 'col', " + "but found '%s' %n", i, cell.getScopeAttribute());
                    }
                    if (!"sansserif".equals(cell.getAttribute("class"))) {
                        formatter.format("Expected class attribute for " + "header cell (%s) to be 'columnClass', " + "but found '%s' %n", i, cell.getAttribute("class"));
                    }
                }
            }
        }
        // There should be one footer containing one row and three td's
        HtmlTableFooter data2Footer = data2.getFooter();
        if (data2Footer == null) {
            formatter.format("Footers not rendered for table containing " + "ID 'data2' when footer facet was specified on " + "the specified columns %n");
        } else {
            // should find 1 header rows
            if (data2Footer.getRows().size() != 1) {
                formatter.format("Expected a single table footer row for " + "table containing ID 'data2', but found '%s' %n", data2Footer.getRows().size());
            } else {
                String[] footerCellValues = new String[] { "", "Gender Footer", "Age Footer" };
                HtmlTableRow row = (HtmlTableRow) data2Footer.getRows().get(0);
                List headerCells = row.getCells();
                for (int i = 0, size = headerCells.size(); i < size; i++) {
                    HtmlTableCell cell = row.getCell(i);
                    if (!footerCellValues[i].equals(cell.asText())) {
                        formatter.format("Expected table footer cell(%s) " + "for table containing ID 'data2' to " + "contain '%s', received: '%s'. %n", i, footerCellValues[i], cell.asText());
                    }
                    // validate no scope attribute is rendered
                    if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("scope"))) {
                        formatter.format("Expected no scope attribute to " + "be rendered for footer cell(%s) in table" + " containing ID 'data2' %n", i);
                    }
                    if (!"sansserif".equals(cell.getAttribute("class"))) {
                        formatter.format("Expected class attribute for " + "footer cell (%s) to be 'columnClass', " + "but found '%s' %n", i, cell.getAttribute("class"));
                    }
                }
            }
        }
        validateTableBodyRows(data2, "data2", null, null, formatter);
        // ---------------------------------------------------------- Data 3
        // this table has headerClass and footerClass defined on the
        // dataTable and column tags. The result is the column level
        // style classes will override the dataTable level classes
        HtmlTable data3 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "data3");
        if (!validateExistence("data3", "table", data3, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // There should be one thead containing one tr and three th's
        HtmlTableHeader data3Header = data3.getHeader();
        if (data3Header == null) {
            formatter.format("Header not rendered for table containing " + "ID 'data3' when header facet was specified on the " + "specified columns %n");
        } else {
            // should find 1 header rows
            if (data3Header.getRows().size() != 1) {
                formatter.format("Expected a single table header row for " + "table containing ID 'data3', but found '%s' %n", data3Header.getRows().size());
            } else {
                String[] headerCellValues = new String[] { "Name Header", "", "Age Header" };
                String[] headerClassValues = new String[] { "columnClass", "sansserif", "sansserif" };
                HtmlTableRow row = (HtmlTableRow) data3Header.getRows().get(0);
                List headerCells = row.getCells();
                for (int i = 0, size = headerCells.size(); i < size; i++) {
                    HtmlTableHeaderCell cell = (HtmlTableHeaderCell) row.getCell(i);
                    if (!headerCellValues[i].equals(cell.asText())) {
                        formatter.format("Expected table header cell(%s) " + "for table containing ID 'data3' to " + "contain '%s', received: '%s'. %n", i, headerCellValues[i], cell.asText());
                    }
                    // column header as expected
                    if (!"col".equals(cell.getScopeAttribute())) {
                        formatter.format("Expected table header cell(%s) " + "for table containing ID 'data3' to have " + "a scope attribute value of 'col', " + "but found '%s' %n", i, cell.getScopeAttribute());
                    }
                    if (!headerClassValues[i].equals(cell.getAttribute("class"))) {
                        formatter.format("Expected class attribute for " + "header cell (%s) to be '%s', but " + "found '%s' %n", i, headerClassValues[i], cell.getAttribute("class"));
                    }
                }
            }
        }
        // There should be one footer containing one row and three td's
        HtmlTableFooter data3Footer = data3.getFooter();
        if (data3Footer == null) {
            formatter.format("Footers not rendered for table containing " + "ID 'data3' when footer facet was specified on the " + "specified columns %n");
        } else {
            // should find 1 header rows
            if (data3Footer.getRows().size() != 1) {
                formatter.format("Expected a single table footer row for " + "table containing ID 'data3', but found '%s' %n", data3Footer.getRows().size());
            } else {
                String[] footerCellValues = new String[] { "", "Gender Footer", "Age Footer" };
                String[] footerClassValues = new String[] { "sansserif", "sansserif", "columnClass" };
                HtmlTableRow row = (HtmlTableRow) data3Footer.getRows().get(0);
                List headerCells = row.getCells();
                for (int i = 0, size = headerCells.size(); i < size; i++) {
                    HtmlTableCell cell = row.getCell(i);
                    if (!footerCellValues[i].equals(cell.asText())) {
                        formatter.format("Expected table footer cell(%s) " + "for table containing ID 'data3' to " + "contain '%s', received: '%s'. %n", i, footerCellValues[i], cell.asText());
                    }
                    // validate no scope attribute is rendered
                    if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(cell.getAttribute("scope"))) {
                        formatter.format("Expected no scope attribute to " + "be rendered for footer cell(%s) in table" + " containing ID 'data3' %n", i);
                    }
                    if (!footerClassValues[i].equals(cell.getAttribute("class"))) {
                        formatter.format("Expected class attribute for " + "footer cell (%s) to be '%s', but " + "found '%s' %n", i, footerClassValues[i], cell.getAttribute("class"));
                    }
                }
            }
        }
        validateTableBodyRows(data3, "data3", null, null, formatter);
        handleTestStatus(messages);
    }
}
Also used : HtmlTableRow(com.gargoylesoftware.htmlunit.html.HtmlTableRow) HtmlTable(com.gargoylesoftware.htmlunit.html.HtmlTable) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Formatter(java.util.Formatter) HtmlTableFooter(com.gargoylesoftware.htmlunit.html.HtmlTableFooter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HtmlTableHeaderCell(com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell) HtmlTableCell(com.gargoylesoftware.htmlunit.html.HtmlTableCell) HtmlTableHeader(com.gargoylesoftware.htmlunit.html.HtmlTableHeader)

Aggregations

HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)4 HtmlTable (com.gargoylesoftware.htmlunit.html.HtmlTable)4 HtmlTableHeaderCell (com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell)4 HtmlTableRow (com.gargoylesoftware.htmlunit.html.HtmlTableRow)4 HtmlTableCell (com.gargoylesoftware.htmlunit.html.HtmlTableCell)3 HtmlTableFooter (com.gargoylesoftware.htmlunit.html.HtmlTableFooter)3 HtmlTableHeader (com.gargoylesoftware.htmlunit.html.HtmlTableHeader)3 ArrayList (java.util.ArrayList)3 Formatter (java.util.Formatter)3 List (java.util.List)3 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)1 HtmlBold (com.gargoylesoftware.htmlunit.html.HtmlBold)1 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlHeading2 (com.gargoylesoftware.htmlunit.html.HtmlHeading2)1 HtmlHeading3 (com.gargoylesoftware.htmlunit.html.HtmlHeading3)1 HtmlImage (com.gargoylesoftware.htmlunit.html.HtmlImage)1 HtmlItalic (com.gargoylesoftware.htmlunit.html.HtmlItalic)1 HtmlParagraph (com.gargoylesoftware.htmlunit.html.HtmlParagraph)1 HtmlPreformattedText (com.gargoylesoftware.htmlunit.html.HtmlPreformattedText)1