Skip to content

Commit b9e516d

Browse files
browser: standard table ignores colspan cells (#1517)
1 parent 1f8b9f1 commit b9e516d

9 files changed

Lines changed: 367 additions & 18 deletions

File tree

webtau-browser/src/main/java/org/testingisdocumenting/webtau/browser/table/BrowserTableParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ private TableData parseAndBuildTable() {
8585
private void handleElement(Element element) {
8686
tableNode.setElement(element);
8787

88+
if (handler.ignore(tableNode)) {
89+
return;
90+
}
91+
8892
if (handler.isHeaderValue(tableNode)) {
8993
if (parsingState == State.PARSING_BODY) {
9094
throw new IllegalStateException("was already parsing body when encountered header");

webtau-browser/src/main/java/org/testingisdocumenting/webtau/browser/table/BrowserTableParserAGGridTableHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public boolean handles(String html) {
2222
return html.contains("ag-cell-value");
2323
}
2424

25+
@Override
26+
public boolean ignore(BrowserTableNode node) {
27+
return false;
28+
}
29+
2530
@Override
2631
public boolean isHeaderValue(BrowserTableNode node) {
2732
return node.attribute("class").contains("ag-header-cell-text");

webtau-browser/src/main/java/org/testingisdocumenting/webtau/browser/table/BrowserTableParserHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
public interface BrowserTableParserHandler {
2020
boolean handles(String html);
2121

22+
boolean ignore(BrowserTableNode node);
23+
2224
boolean isHeaderValue(BrowserTableNode node);
2325

2426
boolean isBodyValue(BrowserTableNode node);

webtau-browser/src/main/java/org/testingisdocumenting/webtau/browser/table/BrowserTableParserStandardTableHandler.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@
1919
public class BrowserTableParserStandardTableHandler implements BrowserTableParserHandler {
2020
@Override
2121
public boolean handles(String html) {
22-
return html.contains("<thead") && html.contains("<th");
22+
return (html.contains("<thead") || html.contains("<tbody")) && html.contains("<th");
23+
}
24+
25+
@Override
26+
public boolean ignore(BrowserTableNode node) {
27+
String colspan = node.attribute("colspan");
28+
if (colspan == null || colspan.isEmpty()) {
29+
return false;
30+
}
31+
32+
return !colspan.equals("1");
2333
}
2434

2535
@Override

webtau-browser/src/test/groovy/org/testingisdocumenting/webtau/browser/table/BrowserTableParserTest.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,20 @@ class BrowserTableParserTest {
3232
"A1" | "B1"
3333
"A2" | "B2" }
3434
}
35+
36+
@Test
37+
void "with ignored col spans"() {
38+
def html = ResourceUtils.textContent("table/tax.html")
39+
def table = BrowserTableParser.parse(html)
40+
41+
table.columnNames.should == [
42+
"At least",
43+
"But less than",
44+
"Single or Married filing separately",
45+
"Married filing jointly*",
46+
"Head of a household" ]
47+
48+
table.row(0).values.should == ['$0', '$13', '$0', '$0', '$0']
49+
table.row(3).values.should == ['50', '100', '3', '3', '3']
50+
}
3551
}
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
<!--
2-
~ Copyright 2023 webtau maintainers
3-
~
4-
~ Licensed under the Apache License, Version 2.0 (the "License");
5-
~ you may not use this file except in compliance with the License.
6-
~ You may obtain a copy of the License at
7-
~
8-
~ http://www.apache.org/licenses/LICENSE-2.0
9-
~
10-
~ Unless required by applicable law or agreed to in writing, software
11-
~ distributed under the License is distributed on an "AS IS" BASIS,
12-
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
~ See the License for the specific language governing permissions and
14-
~ limitations under the License.
15-
-->
16-
171
<body>
182
<table>
193
<thead>
@@ -37,4 +21,4 @@
3721
</tr>
3822
</tbody>
3923
</table>
40-
</body>
24+
</body>

0 commit comments

Comments
 (0)