Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: roll to 1.28.0-beta-1668538774000 #1651

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
get_by_test_id_selector,
get_by_text_selector,
get_by_title_selector,
test_id_attribute_name,
)
from playwright._impl._network import Response
from playwright._impl._set_input_files_helpers import convert_input_files
Expand Down Expand Up @@ -560,6 +561,7 @@ def get_by_role(
name: Union[str, Pattern[str]] = None,
pressed: bool = None,
selected: bool = None,
exact: bool = None,
) -> "Locator":
return self.locator(
get_by_role_selector(
Expand All @@ -572,11 +574,12 @@ def get_by_role(
name=name,
pressed=pressed,
selected=selected,
exact=exact,
)
)

def get_by_test_id(self, testId: str) -> "Locator":
return self.locator(get_by_test_id_selector(testId))
return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId))

def get_by_text(
self, text: Union[str, Pattern[str]], exact: bool = None
Expand Down
25 changes: 17 additions & 8 deletions playwright/_impl/_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def get_by_role(
name: Union[str, Pattern[str]] = None,
pressed: bool = None,
selected: bool = None,
exact: bool = None,
) -> "Locator":
return self.locator(
get_by_role_selector(
Expand All @@ -256,11 +257,12 @@ def get_by_role(
name=name,
pressed=pressed,
selected=selected,
exact=exact,
)
)

def get_by_test_id(self, testId: str) -> "Locator":
return self.locator(get_by_test_id_selector(testId))
return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId))

def get_by_text(
self, text: Union[str, Pattern[str]], exact: bool = None
Expand Down Expand Up @@ -690,6 +692,7 @@ def get_by_role(
name: Union[str, Pattern[str]] = None,
pressed: bool = None,
selected: bool = None,
exact: bool = None,
) -> "Locator":
return self.locator(
get_by_role_selector(
Expand All @@ -702,11 +705,12 @@ def get_by_role(
name=name,
pressed=pressed,
selected=selected,
exact=exact,
)
)

def get_by_test_id(self, testId: str) -> "Locator":
return self.locator(get_by_test_id_selector(testId))
return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId))

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


test_id_attribute_name: str = "data-testid"
_test_id_attribute_name: str = "data-testid"


def test_id_attribute_name() -> str:
return _test_id_attribute_name


def set_test_id_attribute_name(attribute_name: str) -> None:
global test_id_attribute_name
test_id_attribute_name = attribute_name
global _test_id_attribute_name
_test_id_attribute_name = attribute_name


def get_by_test_id_selector(test_id: str) -> str:
return get_by_attribute_text_selector(test_id_attribute_name, test_id, exact=True)
def get_by_test_id_selector(test_id_attribute_name: str, test_id: str) -> str:
return f"internal:testid=[{test_id_attribute_name}=${escape_for_attribute_selector(test_id, True)}]"


def get_by_attribute_text_selector(
Expand Down Expand Up @@ -791,6 +799,7 @@ def get_by_role_selector(
name: Union[str, Pattern[str]] = None,
pressed: bool = None,
selected: bool = None,
exact: bool = None,
) -> str:
props: List[Tuple[str, str]] = []
if checked is not None:
Expand All @@ -811,7 +820,7 @@ def get_by_role_selector(
"name",
f"/{name.pattern}/{escape_regex_flags(name)}"
if isinstance(name, Pattern)
else escape_for_attribute_selector(name),
else escape_for_attribute_selector(name, exact),
)
)
if pressed is not None:
Expand Down
2 changes: 2 additions & 0 deletions playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ def get_by_role(
name: Union[str, Pattern[str]] = None,
pressed: bool = None,
selected: bool = None,
exact: bool = None,
) -> "Locator":
return self._main_frame.get_by_role(
role,
Expand All @@ -784,6 +785,7 @@ def get_by_role(
name=name,
pressed=pressed,
selected=selected,
exact=exact,
)

def get_by_test_id(self, testId: str) -> "Locator":
Expand Down
10 changes: 9 additions & 1 deletion playwright/_impl/_selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from playwright._impl._api_types import Error
from playwright._impl._connection import ChannelOwner
from playwright._impl._helper import async_readfile
from playwright._impl._locator import set_test_id_attribute_name
from playwright._impl._locator import set_test_id_attribute_name, test_id_attribute_name


class Selectors:
Expand Down Expand Up @@ -49,12 +49,20 @@ async def register(

def set_test_id_attribute(self, attribute_name: str) -> None:
set_test_id_attribute_name(attribute_name)
for channel in self._channels:
channel._channel.send_no_reply(
"setTestIdAttributeName", {"testIdAttributeName": attribute_name}
)

def _add_channel(self, channel: "SelectorsOwner") -> None:
self._channels.add(channel)
for params in self._registrations:
# This should not fail except for connection closure, but just in case we catch.
channel._channel.send_no_reply("register", params)
channel._channel.send_no_reply(
"setTestIdAttributeName",
{"testIdAttributeName": test_id_attribute_name()},
)

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