test(eosdash): wait for the htmx swap before checking a tab's content

The browser test read the content area right after the tab's response
arrived. htmx swaps the response in after that, and wait_for_load_state()
did not wait for it, as the page itself was loaded long before. For the
large configuration tab the content area was sometimes still empty, so
the test failed in CI.

Wait until the content area is filled again after a successful response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bobby Noelte
2026-11-09 14:21:51 +01:00
co-authored by Claude Opus 5.5
parent c230d9d9de
commit b92d115a39
+17 -3
View File
@@ -89,21 +89,35 @@ class DashPage:
the previous tab cannot be mistaken for the new tab: htmx does not swap the previous tab cannot be mistaken for the new tab: htmx does not swap
error responses, which leaves the content area empty. error responses, which leaves the content area empty.
htmx swaps the content in after the response has arrived. For a
successful response this waits until the content area is filled again;
``wait_for_load_state()`` would not wait, as the page itself is loaded.
Args: Args:
path: Path of the tab, as in its ``hx-get`` attribute. path: Path of the tab, as in its ``hx-get`` attribute.
Returns: Returns:
HTTP status of the tab request. HTTP status of the tab request.
""" """
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
self.page.eval_on_selector(PAGE_CONTENT_SELECTOR, "element => element.replaceChildren()") self.page.eval_on_selector(PAGE_CONTENT_SELECTOR, "element => element.replaceChildren()")
# The tabs add query values (e.g. dark=true): compare the path only. # The tabs add query values (e.g. dark=true): compare the path only.
with self.page.expect_response( with self.page.expect_response(
lambda response: urlsplit(response.url).path == path lambda response: urlsplit(response.url).path == path
) as response_info: ) as response_info:
self.page.click(f"button[hx-get='{path}']") self.page.click(f"button[hx-get='{path}']")
status = response_info.value.status response = response_info.value
self.page.wait_for_load_state("networkidle") if response.ok:
return status try:
self.page.wait_for_function(
"selector => document.querySelector(selector)?.innerHTML.trim() !== ''",
arg=PAGE_CONTENT_SELECTOR,
)
except PlaywrightTimeoutError:
# Nothing was swapped in; the caller's content check reports it.
pass
return response.status
def wait_for_eosdash(base_url: str) -> None: def wait_for_eosdash(base_url: str) -> None: