Skip to content

Commit 676b956

Browse files
authored
chore: roll to 1.28.0-beta-1668538774000 (#1651)
1 parent ca742b0 commit 676b956

File tree

9 files changed

+264
-83
lines changed

9 files changed

+264
-83
lines changed

playwright/_impl/_frame.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
get_by_test_id_selector,
5656
get_by_text_selector,
5757
get_by_title_selector,
58+
test_id_attribute_name,
5859
)
5960
from playwright._impl._network import Response
6061
from playwright._impl._set_input_files_helpers import convert_input_files
@@ -560,6 +561,7 @@ def get_by_role(
560561
name: Union[str, Pattern[str]] = None,
561562
pressed: bool = None,
562563
selected: bool = None,
564+
exact: bool = None,
563565
) -> "Locator":
564566
return self.locator(
565567
get_by_role_selector(
@@ -572,11 +574,12 @@ def get_by_role(
572574
name=name,
573575
pressed=pressed,
574576
selected=selected,
577+
exact=exact,
575578
)
576579
)
577580

578581
def get_by_test_id(self, testId: str) -> "Locator":
579-
return self.locator(get_by_test_id_selector(testId))
582+
return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId))
580583

581584
def get_by_text(
582585
self, text: Union[str, Pattern[str]], exact: bool = None

playwright/_impl/_locator.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def get_by_role(
244244
name: Union[str, Pattern[str]] = None,
245245
pressed: bool = None,
246246
selected: bool = None,
247+
exact: bool = None,
247248
) -> "Locator":
248249
return self.locator(
249250
get_by_role_selector(
@@ -256,11 +257,12 @@ def get_by_role(
256257
name=name,
257258
pressed=pressed,
258259
selected=selected,
260+
exact=exact,
259261
)
260262
)
261263

262264
def get_by_test_id(self, testId: str) -> "Locator":
263-
return self.locator(get_by_test_id_selector(testId))
265+
return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId))
264266

265267
def get_by_text(
266268
self, text: Union[str, Pattern[str]], exact: bool = None
@@ -690,6 +692,7 @@ def get_by_role(
690692
name: Union[str, Pattern[str]] = None,
691693
pressed: bool = None,
692694
selected: bool = None,
695+
exact: bool = None,
693696
) -> "Locator":
694697
return self.locator(
695698
get_by_role_selector(
@@ -702,11 +705,12 @@ def get_by_role(
702705
name=name,
703706
pressed=pressed,
704707
selected=selected,
708+
exact=exact,
705709
)
706710
)
707711

708712
def get_by_test_id(self, testId: str) -> "Locator":
709-
return self.locator(get_by_test_id_selector(testId))
713+
return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId))
710714

711715
def get_by_text(
712716
self, text: Union[str, Pattern[str]], exact: bool = None
@@ -739,16 +743,20 @@ def __repr__(self) -> str:
739743
return f"<FrameLocator frame={self._frame!r} selector={self._frame_selector!r}>"
740744

741745

742-
test_id_attribute_name: str = "data-testid"
746+
_test_id_attribute_name: str = "data-testid"
747+
748+
749+
def test_id_attribute_name() -> str:
750+
return _test_id_attribute_name
743751

744752

745753
def set_test_id_attribute_name(attribute_name: str) -> None:
746-
global test_id_attribute_name
747-
test_id_attribute_name = attribute_name
754+
global _test_id_attribute_name
755+
_test_id_attribute_name = attribute_name
748756

749757

750-
def get_by_test_id_selector(test_id: str) -> str:
751-
return get_by_attribute_text_selector(test_id_attribute_name, test_id, exact=True)
758+
def get_by_test_id_selector(test_id_attribute_name: str, test_id: str) -> str:
759+
return f"internal:testid=[{test_id_attribute_name}={escape_for_attribute_selector(test_id, True)}]"
752760

753761

754762
def get_by_attribute_text_selector(
@@ -791,6 +799,7 @@ def get_by_role_selector(
791799
name: Union[str, Pattern[str]] = None,
792800
pressed: bool = None,
793801
selected: bool = None,
802+
exact: bool = None,
794803
) -> str:
795804
props: List[Tuple[str, str]] = []
796805
if checked is not None:
@@ -811,7 +820,7 @@ def get_by_role_selector(
811820
"name",
812821
f"/{name.pattern}/{escape_regex_flags(name)}"
813822
if isinstance(name, Pattern)
814-
else escape_for_attribute_selector(name),
823+
else escape_for_attribute_selector(name, exact),
815824
)
816825
)
817826
if pressed is not None:

playwright/_impl/_page.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ def get_by_role(
773773
name: Union[str, Pattern[str]] = None,
774774
pressed: bool = None,
775775
selected: bool = None,
776+
exact: bool = None,
776777
) -> "Locator":
777778
return self._main_frame.get_by_role(
778779
role,
@@ -784,6 +785,7 @@ def get_by_role(
784785
name=name,
785786
pressed=pressed,
786787
selected=selected,
788+
exact=exact,
787789
)
788790

789791
def get_by_test_id(self, testId: str) -> "Locator":

playwright/_impl/_selectors.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from playwright._impl._api_types import Error
2020
from playwright._impl._connection import ChannelOwner
2121
from playwright._impl._helper import async_readfile
22-
from playwright._impl._locator import set_test_id_attribute_name
22+
from playwright._impl._locator import set_test_id_attribute_name, test_id_attribute_name
2323

2424

2525
class Selectors:
@@ -49,12 +49,20 @@ async def register(
4949

5050
def set_test_id_attribute(self, attribute_name: str) -> None:
5151
set_test_id_attribute_name(attribute_name)
52+
for channel in self._channels:
53+
channel._channel.send_no_reply(
54+
"setTestIdAttributeName", {"testIdAttributeName": attribute_name}
55+
)
5256

5357
def _add_channel(self, channel: "SelectorsOwner") -> None:
5458
self._channels.add(channel)
5559
for params in self._registrations:
5660
# This should not fail except for connection closure, but just in case we catch.
5761
channel._channel.send_no_reply("register", params)
62+
channel._channel.send_no_reply(
63+
"setTestIdAttributeName",
64+
{"testIdAttributeName": test_id_attribute_name()},
65+
)
5866

5967
def _remove_channel(self, channel: "SelectorsOwner") -> None:
6068
if channel in self._channels:

0 commit comments

Comments
 (0)