File tree Expand file tree Collapse file tree 4 files changed +31
-3
lines changed Expand file tree Collapse file tree 4 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -75,15 +75,17 @@ def __init__(
75
75
if has_text :
76
76
if isinstance (has_text , Pattern ):
77
77
js_regex = f"/{ has_text .pattern } /{ escape_regex_flags (has_text )} "
78
- self ._selector += f' >> has={ json .dumps ("text=" + js_regex )} '
78
+ self ._selector += (
79
+ f' >> has={ json .dumps ("text=" + js_regex , ensure_ascii = False )} '
80
+ )
79
81
else :
80
82
escaped = escape_with_quotes (has_text , '"' )
81
83
self ._selector += f" >> :scope:has-text({ escaped } )"
82
84
83
85
if has :
84
86
if has ._frame != frame :
85
87
raise Error ('Inner "has" locator must belong to the same frame.' )
86
- self ._selector += " >> has=" + json .dumps (has ._selector )
88
+ self ._selector += " >> has=" + json .dumps (has ._selector , ensure_ascii = False )
87
89
88
90
def __repr__ (self ) -> str :
89
91
return f"<Locator frame={ self ._frame !r} selector={ self ._selector !r} >"
Original file line number Diff line number Diff line change 18
18
19
19
20
20
def escape_with_quotes (text : str , char : str = "'" ) -> str :
21
- stringified = json .dumps (text )
21
+ stringified = json .dumps (text , ensure_ascii = False )
22
22
escaped_text = stringified [1 :- 1 ].replace ('\\ "' , '"' )
23
23
if char == "'" :
24
24
return char + escaped_text .replace ("'" , "\\ '" ) + char
Original file line number Diff line number Diff line change @@ -809,3 +809,16 @@ async def test_should_filter_by_regex_with_special_symbols(page):
809
809
await expect (
810
810
page .locator ("div" , has_text = re .compile (r'^first\/".*"second\\$' , re .S | re .I ))
811
811
).to_have_class ("test" )
812
+
813
+
814
+ async def test_locators_has_does_not_encode_unicode (page : Page , server : Server ):
815
+ await page .goto (server .EMPTY_PAGE )
816
+ locators = [
817
+ page .locator ("button" , has_text = "Драматург" ),
818
+ page .locator ("button" , has_text = re .compile ("Драматург" )),
819
+ page .locator ("button" , has = page .locator ("text=Драматург" )),
820
+ ]
821
+ for locator in locators :
822
+ with pytest .raises (Error ) as exc_info :
823
+ await locator .click (timeout = 1_000 )
824
+ assert "Драматург" in exc_info .value .message
Original file line number Diff line number Diff line change @@ -711,3 +711,16 @@ def test_should_support_locator_filter(page: Page) -> None:
711
711
has_text = "world" ,
712
712
)
713
713
).to_have_count (1 )
714
+
715
+
716
+ def test_locators_has_does_not_encode_unicode (page : Page , server : Server ) -> None :
717
+ page .goto (server .EMPTY_PAGE )
718
+ locators = [
719
+ page .locator ("button" , has_text = "Драматург" ),
720
+ page .locator ("button" , has_text = re .compile ("Драматург" )),
721
+ page .locator ("button" , has = page .locator ("text=Драматург" )),
722
+ ]
723
+ for locator in locators :
724
+ with pytest .raises (Error ) as exc_info :
725
+ locator .click (timeout = 1_000 )
726
+ assert "Драматург" in exc_info .value .message
You can’t perform that action at this time.
0 commit comments