Skip to content

Commit

Permalink
Refactor Playwright tests to use fixtures, refs #19
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 8, 2024
1 parent 502ac1e commit e79f19a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_long_description():
install_requires=["datasette>=0.63.1"],
python_requires=">=3.7",
extras_require={
"test": ["pytest", "pytest-asyncio", "sqlite-utils"],
"test": ["pytest", "pytest-asyncio", "sqlite-utils", "nest-asyncio"],
"playwright": ["pytest-playwright"]
},
)
45 changes: 20 additions & 25 deletions tests/test_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,29 @@
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):
with sync_api.sync_playwright() as playwright:
browser = playwright.chromium.launch()
page = browser.new_page()
page.goto(ds_server + "/")
assert page.title() == "Datasette: data"
# It should have a search form
assert page.query_selector('form[action="/-/search"]')
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"]')


def test_search(ds_server):
with sync_api.sync_playwright() as playwright:
browser = playwright.chromium.launch()
page = browser.new_page()
page.goto(ds_server + "/-/search?q=cleo")
# Should show search results, after fetching them
assert page.locator("table tr th:nth-child(1)").inner_text() == "rowid"
assert page.locator("table tr th:nth-child(2)").inner_text() == "name"
assert page.locator("table tr th:nth-child(3)").inner_text() == "description"
assert page.locator("table tr:nth-child(2) td:nth-child(1)").inner_text() == "1"
assert (
page.locator("table tr:nth-child(2) td:nth-child(2)").inner_text() == "Cleo"
)
assert (
page.locator("table tr:nth-child(2) td:nth-child(3)").inner_text()
== "A medium sized dog"
)
def test_search(ds_server, page):
page.goto(ds_server + "/-/search?q=cleo")
# Should show search results, after fetching them
assert page.locator("table tr th:nth-child(1)").inner_text() == "rowid"
assert page.locator("table tr th:nth-child(2)").inner_text() == "name"
assert page.locator("table tr th:nth-child(3)").inner_text() == "description"
assert page.locator("table tr:nth-child(2) td:nth-child(1)").inner_text() == "1"
assert page.locator("table tr:nth-child(2) td:nth-child(2)").inner_text() == "Cleo"
assert (
page.locator("table tr:nth-child(2) td:nth-child(3)").inner_text()
== "A medium sized dog"
)

0 comments on commit e79f19a

Please sign in to comment.