@@ -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