Skip to content

Commit 28d72d3

Browse files
committed
start to switch test suite to playwright
1 parent 17f6633 commit 28d72d3

File tree

18 files changed

+76
-129
lines changed

18 files changed

+76
-129
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v2
18-
- uses: nanasess/setup-chromedriver@master
1918
- uses: actions/setup-node@v2
2019
with:
2120
node-version: "14.x"
@@ -38,7 +37,6 @@ jobs:
3837
os: [ubuntu-latest, macos-latest, windows-latest]
3938
steps:
4039
- uses: actions/checkout@v2
41-
- uses: nanasess/setup-chromedriver@master
4240
- uses: actions/setup-node@v2
4341
with:
4442
node-version: "14.x"

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_python_suite(session: Session) -> None:
179179
"""Run the Python-based test suite"""
180180
session.env["IDOM_DEBUG_MODE"] = "1"
181181
install_requirements_file(session, "test-env")
182-
182+
session.run("playwright install")
183183
posargs = session.posargs
184184
posargs += ["--reruns", "3", "--reruns-delay", "1"]
185185

requirements/pkg-extras.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# extra=stable,sanic
2-
sanic <19.12.0
2+
sanic
33
sanic-cors
44

55
# extra=fastapi
66
fastapi >=0.63.0
77
uvicorn[standard] >=0.13.4
88

99
# extra=starlette
10-
fastapi >=0.16.0
10+
starlette >=0.13.6
1111
uvicorn[standard] >=0.13.4
1212

1313
# extra=flask

requirements/test-env.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
ipython
22
pytest
3-
pytest-asyncio
3+
pytest-asyncio>=0.17
44
pytest-cov
55
pytest-mock
66
pytest-rerunfailures
77
pytest-timeout
88
responses
9-
selenium
9+
playwright

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ testpaths = tests
2424
xfail_strict = True
2525
markers =
2626
slow: marks tests as slow (deselect with '-m "not slow"')
27-
python_files = assert_*.py test_*.py
27+
python_files = *asserts.py test_*.py
28+
asyncio_mode = auto
2829

2930
[coverage:report]
3031
fail_under = 100

src/idom/sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@component
1313
def App() -> VdomDict:
14-
return html._(
14+
return html.div(
1515
{"style": {"padding": "15px"}},
1616
html.h1("Sample Application"),
1717
html.p(

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .utils.browser import Display

tests/conftest.py

Lines changed: 11 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
from __future__ import annotations
22

3-
import inspect
43
import os
5-
from typing import Any, List
4+
from dataclasses import dataclass
5+
from typing import Awaitable, Callable, List
66

77
import pytest
88
from _pytest.config import Config
99
from _pytest.config.argparsing import Parser
10-
from selenium.webdriver import Chrome, ChromeOptions
11-
from selenium.webdriver.support.ui import WebDriverWait
1210

1311
import idom
14-
from idom.testing import (
15-
ServerMountPoint,
16-
clear_idom_web_modules_dir,
17-
create_simple_selenium_web_driver,
18-
)
12+
from idom.testing import ServerMountPoint, clear_idom_web_modules_dir
13+
from tests.utils.browser import launch_browser, open_display
1914

2015

2116
def pytest_collection_modifyitems(
22-
session: pytest.Session, config: pytest.config.Config, items: List[pytest.Item]
17+
session: pytest.Session, config: Config, items: List[pytest.Item]
2318
) -> None:
24-
_mark_coros_as_async_tests(items)
2519
_skip_web_driver_tests_on_windows(items)
2620

2721

@@ -32,92 +26,25 @@ def pytest_addoption(parser: Parser) -> None:
3226
action="store_true",
3327
help="Whether to run browser tests in headless mode.",
3428
)
35-
parser.addoption(
36-
"--no-restore",
37-
dest="restore_client",
38-
action="store_false",
39-
help="Whether to restore the client build before testing.",
40-
)
4129

4230

4331
@pytest.fixture
44-
def display(driver, server_mount_point):
45-
display_id = idom.Ref(0)
46-
47-
def mount_and_display(component_constructor, query=None, check_mount=True):
48-
component_id = f"display-{display_id.set_current(display_id.current + 1)}"
49-
server_mount_point.mount(
50-
lambda: idom.html.div({"id": component_id}, component_constructor())
51-
)
52-
driver.get(server_mount_point.url(query=query))
53-
if check_mount:
54-
driver.find_element("id", component_id)
55-
return component_id
56-
57-
yield mount_and_display
32+
async def display(browser):
33+
async with open_display(browser, idom.server.any) as display:
34+
yield display
5835

5936

6037
@pytest.fixture
61-
def driver_get(driver, server_mount_point):
62-
return lambda query=None: driver.get(server_mount_point.url(query=query))
63-
64-
65-
@pytest.fixture
66-
async def server_mount_point():
67-
"""An IDOM layout mount function and server as a tuple
68-
69-
The ``mount`` and ``server`` fixtures use this.
70-
"""
71-
async with ServerMountPoint() as mount_point:
72-
yield mount_point
73-
74-
75-
@pytest.fixture(scope="module")
76-
def driver_wait(driver):
77-
return WebDriverWait(driver, 3)
78-
79-
80-
@pytest.fixture(scope="module")
81-
def driver(create_driver) -> Chrome:
82-
"""A Selenium web driver"""
83-
return create_driver()
84-
85-
86-
@pytest.fixture(scope="module")
87-
def create_driver(driver_is_headless):
88-
"""A Selenium web driver"""
89-
drivers = []
90-
91-
def create(**kwargs: Any):
92-
options = ChromeOptions()
93-
options.headless = driver_is_headless
94-
driver = create_simple_selenium_web_driver(driver_options=options, **kwargs)
95-
drivers.append(driver)
96-
return driver
97-
98-
yield create
99-
100-
for d in drivers:
101-
d.quit()
102-
103-
104-
@pytest.fixture(scope="session")
105-
def driver_is_headless(pytestconfig: Config):
106-
return bool(pytestconfig.option.headless)
38+
async def browser(pytestconfig: Config):
39+
async with launch_browser(headless=bool(pytestconfig.option.headless)) as browser:
40+
yield browser
10741

10842

10943
@pytest.fixture(autouse=True)
11044
def _clear_web_modules_dir_after_test():
11145
clear_idom_web_modules_dir()
11246

11347

114-
def _mark_coros_as_async_tests(items: List[pytest.Item]) -> None:
115-
for item in items:
116-
if isinstance(item, pytest.Function):
117-
if inspect.iscoroutinefunction(item.function):
118-
item.add_marker(pytest.mark.asyncio)
119-
120-
12148
def _skip_web_driver_tests_on_windows(items: List[pytest.Item]) -> None:
12249
if os.name == "nt":
12350
for item in items:

tests/driver_utils.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import idom
66
from idom.testing import ServerMountPoint
7-
from tests.driver_utils import send_keys
7+
from tests.utils.browser import send_keys
88

99

1010
JS_DIR = Path(__file__).parent / "js"

0 commit comments

Comments
 (0)