Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public String tagName() {
return element.tagName();
}

public String attribute(String name) {
return element.attributes().get(name);
}

public String html() {
return element.html();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ enum State {
PARSING_BODY
}

private static final List<BrowserTableParserHandler> parserHandlers = ServiceLoaderUtils.load(BrowserTableParserHandler.class);
private static final List<BrowserTableParserHandler> parserHandlers = discoverHandlers();

private final BrowserTableParserHandler handler;
private final String html;
private final BrowserTableNode tableNode;
Expand Down Expand Up @@ -100,4 +101,13 @@ private void handleElement(Element element) {
element.children().forEach(this::handleElement);
}
}

private static List<BrowserTableParserHandler> discoverHandlers() {
ArrayList<BrowserTableParserHandler> result = new ArrayList<>();
result.add(new BrowserTableParserStandardTableHandler());
result.add(new BrowserTableParserAGGridTableHandler());
result.addAll(ServiceLoaderUtils.load(BrowserTableParserHandler.class));

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2023 webtau maintainers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.testingisdocumenting.webtau.browser.table;

public class BrowserTableParserAGGridTableHandler implements BrowserTableParserHandler {
@Override
public boolean handles(String html) {
return html.contains("ag-cell-value");
}

@Override
public boolean isHeaderValue(BrowserTableNode node) {
return node.attribute("class").contains("ag-header-cell-text");
}

@Override
public boolean isBodyValue(BrowserTableNode node) {
return node.attribute("class").contains("ag-cell-value");
}
}

This file was deleted.

6 changes: 6 additions & 0 deletions webtau-docs/znai/browser/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ Java:
surroundedBy: "table-data-validation"
}
```

# Supported Tables Flavor

WebTau supports standard HTML tables and [AG Grid](https://www.ag-grid.com).

There is a mechanism to register new parsers. If you are interested in contributing a parser or learn how to do it, please [create a ticket](https://github.com/testingisdocumenting/webtau/issues)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add: [browser.table AG Grid](browser/tables#supported-tables-flavor) flavor
11 changes: 10 additions & 1 deletion webtau-feature-testing/examples/scenarios/ui/tables.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scenario("open browser") {
browser.open("/tables")
}

scenario("table equality") {
scenario("standard table equality") {
// table-data-validation
def summaryTable = browser.table("#summary")

Expand All @@ -17,3 +17,12 @@ scenario("table equality") {
// table-data-validation
}

scenario("simple ag grid equality") {
def summaryTable = browser.table("#ag-grid-simple")

summaryTable.should == ["column A" | "column B" | "column C"] {
______________________________________
"A1" | "B1" | "C1"
"A2" | "B2" | "C2"
"A3" | "B3" | "C3" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class WebTauBrowserFeaturesTestBase {
}

@Test
void "tables parsing"() {
void "browser tables"() {
runCli("tables.groovy", "webtau.cfg.groovy")
}

Expand Down
31 changes: 31 additions & 0 deletions webtau-feature-testing/src/test/resources/tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
~ limitations under the License.
-->

<head>
<title>Tables</title>
<script src="https://unpkg.com/ag-grid-community/dist/ag-grid-community.min.js"></script>
</head>

<body>
<table id='summary'>
<thead>
Expand All @@ -37,4 +42,30 @@
</tr>
</tbody>
</table>
<div id="ag-grid-simple" style="height: 200px; width:800px;" class="ag-theme-alpine"></div>
<script>
var columnDefs = [
{headerName: "column A", field: "columnA"},
{headerName: "column B", field: "columnB"},
{headerName: "column C", field: "columnC"}
];

var rowData = [
{columnA: "A1", columnB: "B1", columnC: "C1"},
{columnA: "A2", columnB: "B2", columnC: "C2"},
{columnA: "A3", columnB: "B3", columnC: "C3"}
];

// let the grid know which columns and what data to use
var gridOptions = {
columnDefs: columnDefs,
rowData: rowData,
};

// setup the grid after the page has finished loading
document.addEventListener('DOMContentLoaded', function() {
var gridDiv = document.querySelector('#ag-grid-simple');
new agGrid.Grid(gridDiv, gridOptions);
});
</script>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
"numberOfSuccessful" : 2
}
}, {
"scenario" : "table equality",
"scenario" : "standard table equality",
"shortContainerId" : "tables.groovy",
"stepsSummary" : {
"numberOfSuccessful" : 1
}
}, {
"scenario" : "simple ag grid equality",
"shortContainerId" : "tables.groovy",
"stepsSummary" : {
"numberOfSuccessful" : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
"numberOfSuccessful" : 2
}
}, {
"scenario" : "table equality",
"scenario" : "standard table equality",
"shortContainerId" : "tables.groovy",
"stepsSummary" : {
"numberOfSuccessful" : 1
}
}, {
"scenario" : "simple ag grid equality",
"shortContainerId" : "tables.groovy",
"stepsSummary" : {
"numberOfSuccessful" : 1
Expand Down