Skip to content

Commit 4bff63d

Browse files
committed
gui_e2e: create helper functions to check warnings
and use them instead of plain code. follow-up from CMK-34806 Change-Id: Idb496e134b50ceb0d41160ff9a6ec4ac051b6c2f
1 parent eede0e5 commit 4bff63d

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

tests/system/gui/test_hosts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_navigate_to_host_properties(host: HostProperties) -> None:
4848

4949
# - check absence of errors and warnings
5050
expect(host.main_area.locator("div.error")).to_have_count(0)
51-
expect(host.main_area.locator("div.warning")).to_have_count(0)
51+
host.main_area.check_no_warnings()
5252

5353

5454
def test_create_and_delete_a_host(dashboard_page: MainDashboard, test_site: Site) -> None:

tests/system/gui/testlib/playwright/pom/page.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,33 @@ def expect_no_entries(self) -> None:
570570
"""
571571
expect(self.get_text("No entries.")).to_be_visible()
572572

573+
@property
574+
def warning(self) -> Locator:
575+
"""The warning banner shown in the main area, if any."""
576+
return self.locator("div.warning")
577+
578+
def check_warning_shown(self) -> None:
579+
"""Assert that exactly one warning banner is shown."""
580+
expect(self.warning, message="No (single) warning banner is shown").to_have_count(1)
581+
582+
def check_warning_texts(self, *expected_texts: str) -> None:
583+
"""Assert that exactly one warning banner is shown, containing all given texts.
584+
585+
Pass each expected text as a separate positional argument, e.g.
586+
`self.check_warning_texts("hello", "world", "universe", "galaxy")` asserts that a
587+
single warning banner is shown and contains all four texts.
588+
"""
589+
assert expected_texts, "check_warning_texts() requires at least one expected text"
590+
self.check_warning_shown()
591+
for text in expected_texts:
592+
expect(
593+
self.warning, message=f"Warning banner does not contain text: '{text}'"
594+
).to_contain_text(text)
595+
596+
def check_no_warnings(self) -> None:
597+
"""Assert that no warning banner is shown."""
598+
expect(self.warning, message="A warning banner is shown unexpectedly").to_have_count(0)
599+
573600
def locator_via_xpath(self, element: str, text: str) -> Locator:
574601
"""Return a locator defined by element and text via xpath."""
575602
return self.locator(f"//{element}[text() = '{text}']")

0 commit comments

Comments
 (0)