Skip to content

Commit a541d6c

Browse files
authored
Merge pull request #46 from Kitware/playwright-tests
ci(playwright): use playwright for tests instead of selenium
2 parents 61d852d + cdd2e01 commit a541d6c

37 files changed

Lines changed: 148 additions & 147 deletions

.github/workflows/test_and_release.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,6 @@ jobs:
5656
with:
5757
python-version: ${{ matrix.python-version }}
5858

59-
- name: Install Chrome
60-
run: |
61-
sudo apt install google-chrome-stable
62-
63-
- name: Check the console scripts interface
64-
run: |
65-
pip install seleniumbase
66-
seleniumbase
67-
sbase
68-
69-
- name: Install chromedriver
70-
run: |
71-
seleniumbase install chromedriver
72-
7359
- name: Set Up Node
7460
uses: actions/setup-node@v4
7561
with:
@@ -91,11 +77,13 @@ jobs:
9177
run: |
9278
pip install .
9379
pip install -r tests/requirements.txt
80+
# Install playwright requirements
81+
playwright install
9482
# Run the tests with coverage so we get a coverage report too
9583
pip install coverage
96-
# coverage run --source . -m pytest -s .
84+
coverage run --source . -m pytest -s .
9785
# Print the coverage report
98-
# coverage report -m
86+
coverage report -m
9987
10088
- name: Upload Coverage to Codecov
10189
uses: codecov/codecov-action@v3

examples/vue3/js_call.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from trame.app import get_server
2-
from trame_client.widgets import client, html
2+
from trame.widgets import client, html
33
from trame_client.ui.html import DivLayout
44
from trame_client.utils.testing import enable_testing
55

tests/conftest.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
HELPER = FixtureHelper(ROOT_PATH)
77

88

9-
@pytest.fixture()
10-
def baseline_image():
11-
HELPER.remove_page_urls()
12-
yield
13-
HELPER.remove_page_urls()
9+
@pytest.fixture
10+
def ref_dir() -> Path:
11+
return Path(__file__).parent / "refs"
1412

1513

1614
@pytest.fixture

tests/refs/simple_count_1.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- document:
2+
- text: "1"
3+
- button "Add to count"

tests/refs/simple_count_5.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- document:
2+
- text: "5"
3+
- button "Add to count"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- document:
2+
- text: Static text 6 count = 6 tts = 2
3+
- button "Update template"
4+
- button "count++"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- document:
2+
- text: Static text 2 count = 2 tts = 0
3+
- button "Update template"
4+
- button "count++"

tests/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pytest
22
pytest-asyncio
3-
seleniumbase
3+
pytest-playwright
44
pixelmatch
55
Pillow
66
pytest-xprocess
77
trame>=3.6
8-
trame-server>=3
8+
trame-server>=3

tests/test_reactivity.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1+
from playwright.sync_api import expect
12
import pytest
2-
from seleniumbase import SB
3+
4+
from trame_client.utils.testing import assert_snapshot_matches
35

46

57
@pytest.mark.parametrize("server_path", ["examples/test/reactivity.py"])
6-
def test_reactivity(server, baseline_image):
7-
with SB() as sb:
8-
url = f"http://127.0.0.1:{server.port}/"
9-
sb.open(url)
10-
sb.check_window(name="simple_count_1", level=3)
11-
sb.assert_exact_text("1", ".countValue")
12-
assert server.get("count") == 1
13-
sb.click(".plusButton")
14-
sb.assert_exact_text("2", ".countValue")
15-
assert server.get("count") == 2
16-
sb.click(".plusButton")
17-
sb.click(".plusButton")
18-
sb.assert_exact_text("4", ".countValue")
19-
assert server.get("count") == 4
20-
sb.click(".plusButton")
21-
sb.assert_exact_text("5", ".countValue")
22-
assert server.get("count") == 5
23-
sb.check_window(name="simple_count_5", level=3)
8+
def test_reactivity(server, page, ref_dir):
9+
url = f"http://127.0.0.1:{server.port}/"
10+
page.goto(url)
11+
12+
assert_snapshot_matches(page, ref_dir, "simple_count_1")
13+
14+
plus_button = page.locator(".plusButton")
15+
count_value = page.locator(".countValue")
16+
17+
expect(count_value).to_have_text("1")
18+
assert server.get("count") == 1
19+
plus_button.click()
20+
expect(count_value).to_have_text("2")
21+
assert server.get("count") == 2
22+
plus_button.click()
23+
plus_button.click()
24+
expect(count_value).to_have_text("4")
25+
assert server.get("count") == 4
26+
plus_button.click()
27+
expect(count_value).to_have_text("5")
28+
assert server.get("count") == 5
29+
30+
assert_snapshot_matches(page, ref_dir, "simple_count_5")

tests/test_vue23.py

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
11
import pytest
2-
from seleniumbase import SB
3-
from trame_client.utils.testing import wait_for_ready
2+
3+
from playwright.sync_api import expect
4+
from trame_client.utils.testing import assert_snapshot_matches
45

56

67
@pytest.mark.parametrize(
78
"server_path",
89
["examples/vue2/dynamic_template.py"],
910
)
10-
def test_dynamic_template(server, baseline_image):
11-
with SB() as sb:
12-
url = f"http://127.0.0.1:{server.port}/"
13-
sb.open(url)
14-
wait_for_ready(sb, 60)
15-
sb.check_window(name="init", level=3)
16-
sb.assert_exact_text("Static text 2", ".staticDiv")
17-
sb.assert_exact_text("count = 2", ".countDiv")
18-
sb.assert_exact_text("tts = 0", ".ttsDiv")
19-
assert server.get("count") == 2
20-
sb.click(".plusBtn")
21-
sb.click(".plusBtn")
22-
sb.assert_exact_text("Static text 2", ".staticDiv")
23-
assert server.get("count") == 4
24-
sb.assert_exact_text("count = 4", ".countDiv")
25-
sb.assert_exact_text("tts = 0", ".ttsDiv")
26-
sb.click(".updateBtn")
27-
sb.click(".updateBtn")
28-
sb.assert_exact_text("Static text 6", ".staticDiv")
29-
assert server.get("count") == 6
30-
sb.assert_exact_text("count = 6", ".countDiv")
31-
sb.assert_exact_text("tts = 2", ".ttsDiv")
32-
sb.check_window(name="final", level=3)
11+
def test_dynamic_template(server, page, ref_dir):
12+
url = f"http://127.0.0.1:{server.port}/"
13+
page.goto(url)
14+
15+
assert_snapshot_matches(page, ref_dir, "test_dynamic_template_initial")
16+
17+
expect(page.locator(".staticDiv")).to_have_text("Static text 2")
18+
expect(page.locator(".countDiv")).to_have_text("count = 2")
19+
expect(page.locator(".ttsDiv")).to_have_text("tts = 0")
20+
assert server.get("count") == 2
21+
22+
page.locator(".plusBtn").click()
23+
page.locator(".plusBtn").click()
24+
expect(page.locator(".staticDiv")).to_have_text("Static text 2")
25+
assert server.get("count") == 4
26+
expect(page.locator(".countDiv")).to_have_text("count = 4")
27+
expect(page.locator(".ttsDiv")).to_have_text("tts = 0")
28+
page.locator(".updateBtn").click()
29+
page.locator(".updateBtn").click()
30+
expect(page.locator(".staticDiv")).to_have_text("Static text 6")
31+
assert server.get("count") == 6
32+
expect(page.locator(".countDiv")).to_have_text("count = 6")
33+
expect(page.locator(".ttsDiv")).to_have_text("tts = 2")
34+
35+
assert_snapshot_matches(page, ref_dir, "test_dynamic_template_final")
3336

3437

3538
@pytest.mark.parametrize(
3639
"server_path",
3740
["examples/vue2/js_call.py", "examples/vue3/js_call.py"],
3841
)
39-
def test_js_call(server, baseline_image):
40-
with SB() as sb:
41-
url = f"http://127.0.0.1:{server.port}/"
42-
sb.open(url)
43-
wait_for_ready(sb, 60)
44-
sb.assert_exact_text("Alert", ".jsAlert")
45-
assert server.get("message") == "hello world"
46-
sb.click(".alertMsg")
47-
sb.assert_exact_text("hello world", ".jsAlert")
48-
sb.click(".alertMe")
49-
sb.assert_exact_text("Yes me", ".jsAlert")
50-
sb.click(".swapMsg")
51-
assert server.get("message") == "dlrow olleh"
52-
sb.click(".alertMsg")
53-
sb.assert_exact_text("dlrow olleh", ".jsAlert")
42+
def test_js_call(server, page):
43+
url = f"http://127.0.0.1:{server.port}/"
44+
page.goto(url)
45+
46+
expect(page.locator(".jsAlert")).to_have_text("Alert")
47+
assert server.get("message") == "hello world"
48+
page.locator(".alertMsg").click()
49+
expect(page.locator(".jsAlert")).to_have_text("hello world")
50+
page.locator(".alertMe").click()
51+
expect(page.locator(".jsAlert")).to_have_text("Yes me")
52+
page.locator(".swapMsg").click()
53+
assert server.get("message") == "dlrow olleh"
54+
page.locator(".alertMsg").click()
55+
expect(page.locator(".jsAlert")).to_have_text("dlrow olleh")

0 commit comments

Comments
 (0)