12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- from typing import Any , List , Pattern , Union
15
+ from typing import Any , List , Optional , Pattern , Union
16
16
from urllib .parse import urljoin
17
17
18
18
from playwright ._impl ._api_structures import ExpectedTextValue , FrameExpectOptions
@@ -122,11 +122,15 @@ async def to_contain_text(
122
122
expected : Union [List [Union [Pattern , str ]], Pattern , str ],
123
123
use_inner_text : bool = None ,
124
124
timeout : float = None ,
125
+ ignore_case : bool = None ,
125
126
) -> None :
126
127
__tracebackhide__ = True
127
128
if isinstance (expected , list ):
128
129
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 ,
130
134
)
131
135
await self ._expect_impl (
132
136
"to.contain.text.array" ,
@@ -140,7 +144,10 @@ async def to_contain_text(
140
144
)
141
145
else :
142
146
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 ,
144
151
)
145
152
await self ._expect_impl (
146
153
"to.have.text" ,
@@ -158,9 +165,10 @@ async def not_to_contain_text(
158
165
expected : Union [List [Union [Pattern , str ]], Pattern , str ],
159
166
use_inner_text : bool = None ,
160
167
timeout : float = None ,
168
+ ignore_case : bool = None ,
161
169
) -> None :
162
170
__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 )
164
172
165
173
async def to_have_attribute (
166
174
self ,
@@ -335,16 +343,41 @@ async def not_to_have_value(
335
343
__tracebackhide__ = True
336
344
await self ._not .to_have_value (value , timeout )
337
345
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
+
338
368
async def to_have_text (
339
369
self ,
340
370
expected : Union [List [Union [Pattern , str ]], Pattern , str ],
341
371
use_inner_text : bool = None ,
342
372
timeout : float = None ,
373
+ ignore_case : bool = None ,
343
374
) -> None :
344
375
__tracebackhide__ = True
345
376
if isinstance (expected , list ):
346
377
expected_text = to_expected_text_values (
347
- expected , normalize_white_space = True
378
+ expected ,
379
+ normalize_white_space = True ,
380
+ ignore_case = ignore_case ,
348
381
)
349
382
await self ._expect_impl (
350
383
"to.have.text.array" ,
@@ -358,7 +391,7 @@ async def to_have_text(
358
391
)
359
392
else :
360
393
expected_text = to_expected_text_values (
361
- [expected ], normalize_white_space = True
394
+ [expected ], normalize_white_space = True , ignore_case = ignore_case
362
395
)
363
396
await self ._expect_impl (
364
397
"to.have.text" ,
@@ -376,9 +409,10 @@ async def not_to_have_text(
376
409
expected : Union [List [Union [Pattern , str ]], Pattern , str ],
377
410
use_inner_text : bool = None ,
378
411
timeout : float = None ,
412
+ ignore_case : bool = None ,
379
413
) -> None :
380
414
__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 )
382
416
383
417
async def to_be_checked (
384
418
self ,
@@ -568,33 +602,46 @@ async def not_to_be_ok(self) -> None:
568
602
569
603
570
604
def 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 ,
572
609
) -> ExpectedTextValue :
573
610
expected = ExpectedTextValue (
574
611
regexSource = pattern .pattern ,
575
612
regexFlags = escape_regex_flags (pattern ),
576
613
matchSubstring = match_substring ,
577
614
normalizeWhiteSpace = normalize_white_space ,
615
+ ignoreCase = ignore_case ,
578
616
)
617
+ if expected ["ignoreCase" ] is None :
618
+ del expected ["ignoreCase" ]
579
619
return expected
580
620
581
621
582
622
def to_expected_text_values (
583
623
items : Union [List [Pattern ], List [str ], List [Union [str , Pattern ]]],
584
624
match_substring : bool = False ,
585
625
normalize_white_space : bool = False ,
626
+ ignore_case : Optional [bool ] = None ,
586
627
) -> List [ExpectedTextValue ]:
587
628
out : List [ExpectedTextValue ] = []
588
629
assert isinstance (items , list )
589
630
for item in items :
590
631
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 ):
591
642
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
596
645
)
597
646
)
598
- elif isinstance (item , Pattern ):
599
- out .append (expected_regex (item , match_substring , normalize_white_space ))
600
647
return out
0 commit comments