|
1 | 1 | 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 |
4 | 5 |
|
5 | 6 |
|
6 | 7 | @pytest.mark.parametrize( |
7 | 8 | "server_path", |
8 | 9 | ["examples/vue2/dynamic_template.py"], |
9 | 10 | ) |
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") |
33 | 36 |
|
34 | 37 |
|
35 | 38 | @pytest.mark.parametrize( |
36 | 39 | "server_path", |
37 | 40 | ["examples/vue2/js_call.py", "examples/vue3/js_call.py"], |
38 | 41 | ) |
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