Search in sources :

Example 1 with HtmlTableHeader

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

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

the class URLClient method dtableRenderEncodeBasicTest.

/*
   * @class.setup_props: webServerHost; webServerPort; ts_home;
   */
/**
 * @testName: dtableRenderEncodeBasicTest
 * @assertion_ids: PENDING
 * @test_Strategy: Validate the basic rendering of a datatable that has not
 *                 header or footer facets defined at the table or column
 *                 level as well as no caption facet. Table data1: - ensure no
 *                 caption, header, or footers are rendered - ensure the
 *                 dataset was properly iterated through and displayed (no
 *                 class attribute rendered on the tr and td elements) Table
 *                 data2: - same as data1 above, accept the table has
 *                 rowClasses and columnClasses defined as ("odd,even").
 *                 Ensure the class attribute for each row and cell has the
 *                 expected value.
 *
 *                 Table data3: - Use the binging attribute to tie into a
 *                 Backing Bean. Make sure that the follow attributes are
 *                 rendered. - bgcolor - border - title
 *
 * @since 1.2
 */
public void dtableRenderEncodeBasicTest() throws Fault {
    StringBuilder messages = new StringBuilder(128);
    Formatter formatter = new Formatter(messages);
    List<HtmlPage> pages = new ArrayList<HtmlPage>();
    pages.add(getPage(CONTEXT_ROOT + "/faces/encodetestBasic.xhtml"));
    pages.add(getPage(CONTEXT_ROOT + "/faces/encodetestBasic_facelet.xhtml"));
    for (HtmlPage page : pages) {
        // ----------------------------------------------------------- Data1
        HtmlTable data1 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "data1");
        if (!validateExistence("data1", "table", data1, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // rendered.
        if (workAroundCaptionTextBug(data1).length() != 0) {
            formatter.format("Caption incorrectly rendered for table " + "containing ID 'data1'. This DataTable had no " + "caption facet. %n");
        }
        // no header facet for the three columns means no thead elements
        // should have been rendered
        HtmlTableHeader data1Header = data1.getHeader();
        if (data1Header != null) {
            formatter.format("Header incorrectly rendered for table " + "containing ID 'data1'.  This DataTable had no " + "header facets. %n");
        }
        validateTableBodyRows(data1, "data1", null, null, formatter);
        // ---------------------------------------------------------- Data 2
        HtmlTable data2 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "data2");
        if (!validateExistence("data2", "table", data2, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // rendered.
        if (workAroundCaptionTextBug(data2).length() != 0) {
            formatter.format("Caption incorrectly rendered for table " + "containing ID 'data2'.  This DataTable had no " + "caption facet. %n");
        }
        // no header facet for the three columns means no thead elements
        // should have been rendered
        HtmlTableHeader data2Header = data2.getHeader();
        if (data2Header != null) {
            formatter.format("Header incorrectly rendered for table " + "containing ID 'data2'.  This DataTable had no " + "header facets. %n");
        }
        validateTableBodyRows(data2, "data2", new String[] { "odd", "even", "odd" }, new String[] { "even", "odd", "" }, formatter);
        // ---------------------------------------------------------- Data 3
        HtmlTable data3 = (HtmlTable) getElementOfTypeIncludingId(page, "table", "data3");
        if (!validateExistence("data3", "table", data3, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // test for title attribute.
        if (!"Books".equals(data3.getAttribute("title"))) {
            formatter.format("Unexpected value for title attribute for " + "the rendered table element. Expected '%s'%n," + " but received '%s'%n", "Books", data3.getAttribute("title"));
        }
        // test for bgcolor attribute.
        if (!"FFFF99".equals(data3.getBgcolorAttribute())) {
            formatter.format("Unexpected value for bgcolor attribute for " + "the rendered table element. Expected '%s'%n," + " but received '%s'%n", "FFFF99", data3.getBgcolorAttribute());
        }
        // test for border attribute.
        if (!"2".equals(data3.getBorderAttribute())) {
            formatter.format("Unexpected value for border attribute for " + "the rendered table element. Expected '%s'%n," + " but received '%s'%n", "2", data3.getBorderAttribute());
        }
        handleTestStatus(messages);
    }
}
Also used : HtmlTable(com.gargoylesoftware.htmlunit.html.HtmlTable) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Formatter(java.util.Formatter) ArrayList(java.util.ArrayList) HtmlTableHeader(com.gargoylesoftware.htmlunit.html.HtmlTableHeader)

Example 3 with HtmlTableHeader

use of com.gargoylesoftware.htmlunit.html.HtmlTableHeader 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 4 with HtmlTableHeader

use of com.gargoylesoftware.htmlunit.html.HtmlTableHeader 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 5 with HtmlTableHeader

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

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