1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from typing import Any , List , Pattern , Union
15+ from typing import Any , List , Optional , Pattern , Union
1616from urllib .parse import urljoin
1717
1818from playwright ._impl ._api_structures import ExpectedTextValue , FrameExpectOptions
@@ -122,11 +122,15 @@ async def to_contain_text(
122122 expected : Union [List [Union [Pattern , str ]], Pattern , str ],
123123 use_inner_text : bool = None ,
124124 timeout : float = None ,
125+ ignore_case : bool = None ,
125126 ) -> None :
126127 __tracebackhide__ = True
127128 if isinstance (expected , list ):
128129 expected_text = to_expected_text_values (
129- expected , match_substring = True , normalize_white_space = True
130+ expected ,
131+ match_substring = True ,
132+ normalize_white_space = True ,
133+ ignore_case = ignore_case ,
130134 )
131135 await self ._expect_impl (
132136 "to.contain.text.array" ,
@@ -140,7 +144,10 @@ async def to_contain_text(
140144 )
141145 else :
142146 expected_text = to_expected_text_values (
143- [expected ], match_substring = True , normalize_white_space = True
147+ [expected ],
148+ match_substring = True ,
149+ normalize_white_space = True ,
150+ ignore_case = ignore_case ,
144151 )
145152 await self ._expect_impl (
146153 "to.have.text" ,
@@ -158,9 +165,10 @@ async def not_to_contain_text(
158165 expected : Union [List [Union [Pattern , str ]], Pattern , str ],
159166 use_inner_text : bool = None ,
160167 timeout : float = None ,
168+ ignore_case : bool = None ,
161169 ) -> None :
162170 __tracebackhide__ = True
163- await self ._not .to_contain_text (expected , use_inner_text , timeout )
171+ await self ._not .to_contain_text (expected , use_inner_text , timeout , ignore_case )
164172
165173 async def to_have_attribute (
166174 self ,
@@ -335,16 +343,41 @@ async def not_to_have_value(
335343 __tracebackhide__ = True
336344 await self ._not .to_have_value (value , timeout )
337345
346+ async def to_have_values (
347+ self ,
348+ values : List [Union [Pattern , str ]],
349+ timeout : float = None ,
350+ ) -> None :
351+ __tracebackhide__ = True
352+ expected_text = to_expected_text_values (values )
353+ await self ._expect_impl (
354+ "to.have.values" ,
355+ FrameExpectOptions (expectedText = expected_text , timeout = timeout ),
356+ values ,
357+ "Locator expected to have Values" ,
358+ )
359+
360+ async def not_to_have_values (
361+ self ,
362+ values : List [Union [Pattern , str ]],
363+ timeout : float = None ,
364+ ) -> None :
365+ __tracebackhide__ = True
366+ await self ._not .to_have_values (values , timeout )
367+
338368 async def to_have_text (
339369 self ,
340370 expected : Union [List [Union [Pattern , str ]], Pattern , str ],
341371 use_inner_text : bool = None ,
342372 timeout : float = None ,
373+ ignore_case : bool = None ,
343374 ) -> None :
344375 __tracebackhide__ = True
345376 if isinstance (expected , list ):
346377 expected_text = to_expected_text_values (
347- expected , normalize_white_space = True
378+ expected ,
379+ normalize_white_space = True ,
380+ ignore_case = ignore_case ,
348381 )
349382 await self ._expect_impl (
350383 "to.have.text.array" ,
@@ -358,7 +391,7 @@ async def to_have_text(
358391 )
359392 else :
360393 expected_text = to_expected_text_values (
361- [expected ], normalize_white_space = True
394+ [expected ], normalize_white_space = True , ignore_case = ignore_case
362395 )
363396 await self ._expect_impl (
364397 "to.have.text" ,
@@ -376,9 +409,10 @@ async def not_to_have_text(
376409 expected : Union [List [Union [Pattern , str ]], Pattern , str ],
377410 use_inner_text : bool = None ,
378411 timeout : float = None ,
412+ ignore_case : bool = None ,
379413 ) -> None :
380414 __tracebackhide__ = True
381- await self ._not .to_have_text (expected , use_inner_text , timeout )
415+ await self ._not .to_have_text (expected , use_inner_text , timeout , ignore_case )
382416
383417 async def to_be_checked (
384418 self ,
@@ -568,33 +602,46 @@ async def not_to_be_ok(self) -> None:
568602
569603
570604def expected_regex (
571- pattern : Pattern , match_substring : bool , normalize_white_space : bool
605+ pattern : Pattern ,
606+ match_substring : bool ,
607+ normalize_white_space : bool ,
608+ ignore_case : Optional [bool ] = None ,
572609) -> ExpectedTextValue :
573610 expected = ExpectedTextValue (
574611 regexSource = pattern .pattern ,
575612 regexFlags = escape_regex_flags (pattern ),
576613 matchSubstring = match_substring ,
577614 normalizeWhiteSpace = normalize_white_space ,
615+ ignoreCase = ignore_case ,
578616 )
617+ if expected ["ignoreCase" ] is None :
618+ del expected ["ignoreCase" ]
579619 return expected
580620
581621
582622def to_expected_text_values (
583623 items : Union [List [Pattern ], List [str ], List [Union [str , Pattern ]]],
584624 match_substring : bool = False ,
585625 normalize_white_space : bool = False ,
626+ ignore_case : Optional [bool ] = None ,
586627) -> List [ExpectedTextValue ]:
587628 out : List [ExpectedTextValue ] = []
588629 assert isinstance (items , list )
589630 for item in items :
590631 if isinstance (item , str ):
632+ o = ExpectedTextValue (
633+ string = item ,
634+ matchSubstring = match_substring ,
635+ normalizeWhiteSpace = normalize_white_space ,
636+ ignoreCase = ignore_case ,
637+ )
638+ if o ["ignoreCase" ] is None :
639+ del o ["ignoreCase" ]
640+ out .append (o )
641+ elif isinstance (item , Pattern ):
591642 out .append (
592- ExpectedTextValue (
593- string = item ,
594- matchSubstring = match_substring ,
595- normalizeWhiteSpace = normalize_white_space ,
643+ expected_regex (
644+ item , match_substring , normalize_white_space , ignore_case
596645 )
597646 )
598- elif isinstance (item , Pattern ):
599- out .append (expected_regex (item , match_substring , normalize_white_space ))
600647 return out
0 commit comments