⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmltablestest.java

📁 这是远程web服务调用的一个包,可以将JSP直接作为服务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        WebTable table = page.getTables()[0];        assertEquals( 3, table.getRowCount() );        assertEquals( 3, table.getColumnCount() );        assertEquals( "gules", table.getCellAsText( 1, 1 ) );        assertEquals( "gules", table.getCellAsText( 2, 1 ) );        assertEquals( "vert",  table.getCellAsText( 2, 2 ) );        assertSame( table.getTableCell( 1, 1 ), table.getTableCell( 2, 1 ) );    }    public void testMissingColumns() throws Exception {        defineWebPage( "Default", "<h2>Interesting data</h2>" +                                  "<table summary=\"tough luck\">" +                                  "<tr><th colspan=2>Colors</th><th>Names</th></tr>" +                                  "<tr><td>Red</td><td rowspan=\"2\"><b>gules</b></td></tr>" +                                  "<tr><td>Green</td><td><a href=\"nowhere\">vert</a></td></tr>" +                                  "</table>" );        WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );        WebTable table = page.getTables()[0];        table.purgeEmptyCells();        assertEquals( 3, table.getRowCount() );        assertEquals( 3, table.getColumnCount() );    }    public void testInnerTableSeek() throws Exception {        defineWebPage( "Default", "<h2>Interesting data</h2>" +                                  "<table id=you summary=\"outer one\">" +                                  "<tr><td>Here we are</td><td>" +                                  "Inner Table 1<br>" +                                  "<table id=you summary='inner zero'>" +                                  "        <tr><td colspan=2>&nbsp;</td></tr>" +                                  "        <tr><td>\nRed\n</td><td>1</td></tr>" +                                  "        <tr><td>Blue</td><td>2</td></tr>" +                                  "</table></td><td>" +                                  "Inner Table 2<br>" +                                  "<table id=me summary=\"inner one\">" +                                  "        <tr><td colspan=2>&nbsp;</td></tr>" +                                  "        <tr><td>Black</td><td>1</td></tr>" +                                  "        <tr><td>White</td><td>2</td></tr>" +                                  "</table></td></tr>" +                                  "</table>" );        WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );        WebTable wt = page.getTableStartingWith( "Red" );        assertNotNull( "Did not find table starting with 'Red'", wt );        String[][] cells = wt.asText();        assertEquals( "Non-blank rows",    2, cells.length );        assertEquals( "Non-blank columns", 2, cells[0].length );        assertEquals( "cell at 1,0",       "Blue", cells[1][0] );        wt = page.getTableStartingWithPrefix( "Re" );        assertNotNull( "Did not find table starting with prefix 'Re'", wt );        cells = wt.asText();        assertEquals( "Non-blank rows",    2, cells.length );        assertEquals( "Non-blank columns", 2, cells[0].length );        assertEquals( "cell at 1,0",       "Blue", cells[1][0] );        wt = page.getTableWithSummary( "Inner One" );        assertNotNull( "Did not find table with summary 'Inner One'", wt );        cells = wt.asText();        assertEquals( "Total rows",    3, cells.length );        assertEquals( "Total columns", 2, cells[0].length );        assertEquals( "cell at 2,0",       "White", cells[2][0] );        wt = page.getTableWithID( "me" );        assertNotNull( "Did not find table with id 'me'", wt );        cells = wt.asText();        assertEquals( "Total rows",    3, cells.length );        assertEquals( "Total columns", 2, cells[0].length );        assertEquals( "cell at 2,0",       "White", cells[2][0] );    }    public void testSpanOverEmptyColumns() throws Exception {        defineWebPage( "Default", "<h2>Interesting data</h2>" +                                  "<table summary=little>" +                                  "<tr><td colspan=2>Title</td><td>Data</td></tr>" +                                  "<tr><td>Name</td><td>&nbsp;</td><td>Value</td></tr>" +                                  "<tr><td>Name</td><td>&nbsp;</td><td>Value</td></tr>" +                                  "</table>" );        WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );        String[][] cells = page.getTableStartingWith( "Title" ).asText();        assertEquals( "Non-blank rows",    3, cells.length );        assertEquals( "Non-blank columns", 2, cells[0].length );        assertEquals( "cell at 1,1",       "Value", cells[1][1] );    }    public void testSpanOverAllEmptyColumns() throws Exception {        defineWebPage( "Default", "<h2>Interesting data</h2>" +                                  "<table summary=little>" +                                  "<tr><td colspan=2>Title</td><td>Data</td></tr>" +                                  "<tr><td>&nbsp;</td><td>&nbsp;</td><td>Value</td></tr>" +                                  "<tr><td>&nbsp;</td><td>&nbsp;</td><td>Value</td></tr>" +                                  "</table>" );        WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );        String[][] cells = page.getTableStartingWith( "Title" ).asText();        assertEquals( "Non-blank rows",    3, cells.length );        assertEquals( "Non-blank columns", 2, cells[0].length );        assertEquals( "cell at 1,1",       "Value", cells[1][1] );    }    public void testTableInParagraph() throws Exception {        defineWebPage( "Default", "<p>" +                                  "<table summary=little>" +                                  "<tr><td>a</td><td>b</td><td>Value</td></tr>" +                                  "<tr><td>c</td><td>d</td><td>Value</td></tr>" +                                  "</table></p>" );        WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );        assertEquals( "Number of tables in paragraph", 1, page.getTextBlocks()[0].getTables().length );        assertEquals( "Number of tables in page", 1, page.getTables().length );    }    /**     * Get a specific cell with a given id in a WebTable     **/    public void testCellsWithID() throws Exception {        defineWebPage( "Default", "<h2>Interesting data</h2>" +                                  "<table id=\"table\" summary=little>" +                                  "<tr><td>Title</td><td>Data</td></tr>" +                                  "<tr><td id=\"id1\">value1</td><td id=\"id2\">value2</td><td>Value</td></tr>" +                                  "<tr><td>&nbsp;</td><td>&nbsp;</td><td>Value</td></tr>" +                                  "</table>" );        WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );        WebTable table = page.getTableWithID("table");        assertNotNull("there is a table",table);        TableCell cell = table.getTableCellWithID("id1");        assertNotNull("cell id1",cell);        assertEquals("Value of cell id1","value1",cell.getText());        cell = table.getTableCellWithID("id2");        assertNotNull("cell id2",cell);        assertEquals("Value of cell id2","value2",cell.getText());        // test non existent cell id        cell = table.getTableCellWithID("nonExistingID");        assertNull("cell id2",cell);        cell = (TableCell) page.getElementWithID( "id1" );        assertEquals( "value of cell found from page", "value1", cell.getText() );    }    /**     * Test that the tag name can be extracted for a cell.     */    public void testCellTagName() throws Exception {        WebTable table = _wc.getResponse( getHostPath() + "/OneTable.html" ).getTables()[0];        assertEquals("Tag name of header cell", table.getTableCell(0,0).getTagName().toUpperCase(), "TH");        assertEquals("Tag name of non-header cell", table.getTableCell(0,1).getTagName().toUpperCase(), "TD");    }    private WebConversation _wc;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -