Skip to content

Commit 7473cea

Browse files
committed
Refactor bookmark tests to wait for URL change
Introduced a shared wait_for_url_change utility and updated all relevant Playwright bookmark tests to wait for the URL to change after clicking the bookmark button. This improves test reliability by ensuring the bookmark action completes before proceeding. Also added missing __init__.py files to ensure proper package structure.
1 parent d656fdb commit 7473cea

File tree

12 files changed

+55
-2
lines changed

12 files changed

+55
-2
lines changed

tests/playwright/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Makes playwright a package
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Makes ai_generated_apps a package
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Makes bookmark a package

tests/playwright/ai_generated_apps/bookmark/accordion/test_accordion_bookmarking.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from shiny.playwright import controller
44
from shiny.pytest import create_app_fixture
55
from shiny.run import ShinyAppProc
6+
from tests.playwright.ai_generated_apps.bookmark.bookmark_utils import (
7+
wait_for_url_change,
8+
)
69

710
app = create_app_fixture(["app-express.py"])
811

@@ -19,10 +22,13 @@ def test_accordion_bookmarking_demo(page: Page, app: ShinyAppProc) -> None:
1922
acc_mod.expect_open(["Section A"])
2023
acc_mod.set(["Section C"])
2124

25+
existing_url = page.url
2226
# click bookmark button
2327
bookmark_button = controller.InputBookmarkButton(page)
2428
bookmark_button.click()
2529

30+
wait_for_url_change(page, existing_url)
31+
2632
# reload page
2733
page.reload()
2834

@@ -32,8 +38,12 @@ def test_accordion_bookmarking_demo(page: Page, app: ShinyAppProc) -> None:
3238
acc_single.set([])
3339
acc_mod.set([])
3440

41+
existing_url = page.url
42+
3543
bookmark_button.click()
3644

45+
wait_for_url_change(page, existing_url)
46+
3747
# reload page
3848
page.reload()
3949

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from playwright.sync_api import Page
2+
3+
4+
def wait_for_url_change(page: Page, existing_url: str, timeout: int = 5000):
5+
page.wait_for_url(lambda url: url != existing_url, timeout=timeout)

tests/playwright/ai_generated_apps/bookmark/input_checkbox/test_input_checkbox_express_bookmarking.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from shiny.playwright import controller
44
from shiny.pytest import create_app_fixture
55
from shiny.run import ShinyAppProc
6+
from tests.playwright.ai_generated_apps.bookmark.bookmark_utils import (
7+
wait_for_url_change,
8+
)
69

710
app = create_app_fixture(["app-express.py"])
811

@@ -33,9 +36,12 @@ def test_checkbox_demo(page: Page, app: ShinyAppProc) -> None:
3336
module_checkbox.expect_checked(True)
3437
module_text.expect_value("Checkbox value: True")
3538

39+
existing_url = page.url
3640
bookmark_button = controller.InputBookmarkButton(page)
3741
bookmark_button.click()
3842

43+
wait_for_url_change(page, existing_url)
44+
3945
# reload the page to test bookmark
4046
page.reload()
4147

tests/playwright/ai_generated_apps/bookmark/input_checkbox_group/test_input_checkbox_group_express_bookmarking.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from shiny.playwright import controller
44
from shiny.pytest import create_app_fixture
55
from shiny.run import ShinyAppProc
6+
from tests.playwright.ai_generated_apps.bookmark.bookmark_utils import (
7+
wait_for_url_change,
8+
)
69

710
app = create_app_fixture(["app-express.py"])
811

@@ -35,9 +38,11 @@ def test_checkbox_group_demo(page: Page, app: ShinyAppProc) -> None:
3538
module_group.expect_selected(["Choice A", "Choice C"])
3639
module_text.expect_value("Checkbox group values: ('Choice A', 'Choice C')")
3740

41+
existing_url = page.url
3842
# Bookmark the state
3943
bookmark_button = controller.InputBookmarkButton(page)
4044
bookmark_button.click()
45+
wait_for_url_change(page, existing_url)
4146

4247
# Reload the page to test bookmark
4348
page.reload()

tests/playwright/ai_generated_apps/bookmark/input_file/test_input_file_express_bookmarking.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from shiny.playwright import controller
44
from shiny.pytest import create_app_fixture
55
from shiny.run import ShinyAppProc
6+
from tests.playwright.ai_generated_apps.bookmark.bookmark_utils import (
7+
wait_for_url_change,
8+
)
69

710
app = create_app_fixture(["app-express.py"])
811

@@ -44,9 +47,12 @@ def test_file_input_bookmarking(page: Page, app: ShinyAppProc) -> None:
4447

4548
mod_file_output_txt.expect_value("File name(s): users.csv, users2.csv")
4649

50+
existing_url = page.url
51+
4752
# click bookmark button
4853
bookmark_button = controller.InputBookmarkButton(page)
4954
bookmark_button.click()
55+
wait_for_url_change(page, existing_url)
5056

5157
page.reload()
5258

tests/playwright/ai_generated_apps/bookmark/input_password/test_input_password_express_bookmarking.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from shiny.playwright import controller
44
from shiny.pytest import create_app_fixture
55
from shiny.run import ShinyAppProc
6+
from tests.playwright.ai_generated_apps.bookmark.bookmark_utils import (
7+
wait_for_url_change,
8+
)
69

710
app = create_app_fixture(["app-express.py"])
811

@@ -46,8 +49,11 @@ def test_text_input_demo(page: Page, app: ShinyAppProc) -> None:
4649

4750
# click bookmark button
4851
bookmark_button = controller.InputBookmarkButton(page)
52+
existing_url = page.url
4953
bookmark_button.click()
5054

55+
wait_for_url_change(page, existing_url)
56+
5157
page.reload()
5258

5359
# Check if the values are retained after reloading the page

tests/playwright/ai_generated_apps/bookmark/navsets/test_navsets_express_bookmarking.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from shiny.playwright import controller
77
from shiny.pytest import create_app_fixture
88
from shiny.run import ShinyAppProc
9+
from tests.playwright.ai_generated_apps.bookmark.bookmark_utils import (
10+
wait_for_url_change,
11+
)
912

1013
app = create_app_fixture("app-express.py")
1114

@@ -44,9 +47,11 @@ def test_navsets_bookmarking_demo(
4447
mod_navset_cont = navset_controller(page, f"first-{navset_name}_{navset_variant}")
4548
mod_navset_cont.set(f"{navset_name}_b")
4649

50+
existing_url = page.url
51+
4752
# Click bookmark button
4853
controller.InputBookmarkButton(page).click()
49-
54+
wait_for_url_change(page, existing_url)
5055
# Reload page
5156
page.reload()
5257

@@ -55,3 +60,4 @@ def test_navsets_bookmarking_demo(
5560
navset_cont.expect_value(f"{navset_name}_c")
5661
mod_navset_collection.expect_value(navset_name)
5762
mod_navset_cont.expect_value(f"{navset_name}_b")
63+
mod_navset_cont.expect_value(f"{navset_name}_b")

0 commit comments

Comments
 (0)