-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_playwright.py
50 lines (42 loc) · 1.25 KB
/
test_playwright.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
try:
from playwright import sync_api
except ImportError:
sync_api = None
import pytest
import nest_asyncio
nest_asyncio.apply()
pytestmark = pytest.mark.skipif(sync_api is None, reason="playwright not installed")
def test_ds_server(ds_server, page):
page.goto(ds_server + "/")
assert page.title() == "Datasette: data"
# It should have a search form
assert page.query_selector('form[action="/-/search"]')
table_js = """
function tableToJson() {
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(),
);
}),
};
});
}
"""
def test_search(ds_server, page):
page.goto(ds_server + "/-/search?q=cleo")
# Should show search results, after fetching them
page.wait_for_selector("table")
table = page.evaluate(table_js)
assert table == [
{
"headers": ["rowid", "name", "description"],
"rows": [["1", "Cleo", "A medium sized dog"]],
},
]