Skip to content

Commit

Permalink
🧵 Fix race condition in test
Browse files Browse the repository at this point in the history
Clicking the accept button fires a fetch call, which sometimes
completes before playwright navigates to the page again,
sometimes not.

This results in the accepted cookies state not being recorded,
in turn causing the test to fail.

Adding an assertion guarantees that the fetch call completed
before we 'refresh' the page.
  • Loading branch information
sergei-maertens committed May 10, 2024
1 parent b1c9518 commit 9470190
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/test_javascript_cookiebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def test_cookiebar_not_shown_anymore_after_accept_or_decline(btn_text: str, page
def test_on_accept_handler_runs_on_load(page: Page, live_server):
accept_button = page.get_by_role("button", name="Accept")
accept_button.click()
# wait for fetch calls to complete & avoid test race conditions...
share_button = page.get_by_role("button", name="SHARE")
expect(share_button).to_be_visible()

test_page_url = f"{live_server.url}{reverse('test_page')}"
page.goto(test_page_url)
Expand Down

0 comments on commit 9470190

Please sign in to comment.