Search in sources :

Example 1 with HtmlTableFooter

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

the class HtmlSerializerVisibleText method appendTable.

/**
 * Process {@link HtmlTable}.
 *
 * @param builder the StringBuilder to add to
 * @param htmlTable the target to process
 * @param mode the {@link Mode} to use for processing
 */
protected void appendTable(final HtmlSerializerTextBuilder builder, final HtmlTable htmlTable, final Mode mode) {
    builder.appendBlockSeparator();
    final String caption = htmlTable.getCaptionText();
    if (caption != null) {
        builder.append(caption, mode);
        builder.appendBlockSeparator();
    }
    boolean first = true;
    // first thead has to be displayed first and first tfoot has to be displayed last
    final HtmlTableHeader tableHeader = htmlTable.getHeader();
    if (tableHeader != null) {
        first = appendTableRows(builder, mode, tableHeader.getRows(), true, null, null);
    }
    final HtmlTableFooter tableFooter = htmlTable.getFooter();
    final List<HtmlTableRow> tableRows = htmlTable.getRows();
    first = appendTableRows(builder, mode, tableRows, first, tableHeader, tableFooter);
    if (tableFooter != null) {
        first = appendTableRows(builder, mode, tableFooter.getRows(), first, null, null);
    } else if (tableRows.isEmpty()) {
        final DomNode firstChild = htmlTable.getFirstChild();
        if (firstChild != null) {
            appendNode(builder, firstChild, mode);
        }
    }
    builder.appendBlockSeparator();
}
Also used : HtmlTableRow(com.gargoylesoftware.htmlunit.html.HtmlTableRow) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HtmlTableFooter(com.gargoylesoftware.htmlunit.html.HtmlTableFooter) HtmlTableHeader(com.gargoylesoftware.htmlunit.html.HtmlTableHeader)

Example 2 with HtmlTableFooter

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

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

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

Example 5 with HtmlTableFooter

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

the class HtmlSerializerNormalizedText method appendTable.

/**
 * Process {@link HtmlTable}.
 *
 * @param builder the StringBuilder to add to
 * @param htmlTable the target to process
 */
protected void appendTable(final HtmlSerializerTextBuilder builder, final HtmlTable htmlTable) {
    builder.appendBlockSeparator();
    final String caption = htmlTable.getCaptionText();
    if (caption != null) {
        builder.append(caption, Mode.NORMALIZE);
        builder.appendBlockSeparator();
    }
    boolean first = true;
    // first thead has to be displayed first and first tfoot has to be displayed last
    final HtmlTableHeader tableHeader = htmlTable.getHeader();
    if (tableHeader != null) {
        first = appendTableRows(builder, tableHeader.getRows(), true, null, null);
    }
    final HtmlTableFooter tableFooter = htmlTable.getFooter();
    final List<HtmlTableRow> tableRows = htmlTable.getRows();
    first = appendTableRows(builder, tableRows, first, tableHeader, tableFooter);
    if (tableFooter != null) {
        first = appendTableRows(builder, tableFooter.getRows(), first, null, null);
    } else if (tableRows.isEmpty()) {
        final DomNode firstChild = htmlTable.getFirstChild();
        if (firstChild != null) {
            appendNode(builder, firstChild);
        }
    }
    builder.appendBlockSeparator();
}
Also used : HtmlTableRow(com.gargoylesoftware.htmlunit.html.HtmlTableRow) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HtmlTableFooter(com.gargoylesoftware.htmlunit.html.HtmlTableFooter) HtmlTableHeader(com.gargoylesoftware.htmlunit.html.HtmlTableHeader)

Aggregations

HtmlTableFooter (com.gargoylesoftware.htmlunit.html.HtmlTableFooter)5 HtmlTableHeader (com.gargoylesoftware.htmlunit.html.HtmlTableHeader)5 HtmlTableRow (com.gargoylesoftware.htmlunit.html.HtmlTableRow)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 HtmlTable (com.gargoylesoftware.htmlunit.html.HtmlTable)3 HtmlTableCell (com.gargoylesoftware.htmlunit.html.HtmlTableCell)3 HtmlTableHeaderCell (com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell)3 ArrayList (java.util.ArrayList)3 Formatter (java.util.Formatter)3 List (java.util.List)3 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)2