Skip to content

Commit

Permalink
Neater JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 4, 2024
1 parent 5cb16b9 commit 46bcf8e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions tests/test_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ def test_ds_server(ds_server, page):

table_js = """
function tableToJson() {
const tables = document.querySelectorAll('table');
return Array.from(tables).map(table => {
const headers = Array.from(table.querySelectorAll('th')).map(th => th.textContent.trim());
const rows = Array.from(table.querySelectorAll('tr')).slice(1).map(tr => {
const cells = Array.from(tr.querySelectorAll('td, th')).map(cell => cell.textContent.trim());
return cells;
});
return {
headers: headers,
rows: rows
};
});
return Array.from(document.querySelectorAll("table")).map((table) => {
return {
headers: Array.from(table.querySelectorAll("th")).map((th) =>
th.textContent.trim(),
),
rows: Array.from(table.querySelectorAll("tr"))
.slice(1)
.map((tr) => {
return Array.from(tr.querySelectorAll("td")).map((cell) =>
cell.textContent.trim(),
);
}),
};
});
}
"""

Expand Down

0 comments on commit 46bcf8e

Please sign in to comment.