From 9470190c59aa620504b52b5d6395d8ff36a70a38 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Fri, 10 May 2024 08:20:24 +0200 Subject: [PATCH] :thread: Fix race condition in test 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. --- tests/test_javascript_cookiebar.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_javascript_cookiebar.py b/tests/test_javascript_cookiebar.py index 5875e9a..245d16b 100644 --- a/tests/test_javascript_cookiebar.py +++ b/tests/test_javascript_cookiebar.py @@ -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)