diff --git a/playwright/_impl/_frame.py b/playwright/_impl/_frame.py index 2ccb8da6c..ca7f4cccb 100644 --- a/playwright/_impl/_frame.py +++ b/playwright/_impl/_frame.py @@ -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 @@ -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( @@ -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 diff --git a/playwright/_impl/_locator.py b/playwright/_impl/_locator.py index f1ef26186..1597a66f3 100644 --- a/playwright/_impl/_locator.py +++ b/playwright/_impl/_locator.py @@ -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( @@ -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 @@ -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( @@ -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 @@ -739,16 +743,20 @@ def __repr__(self) -> str: return f"" -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( @@ -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: @@ -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: diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index 31b058f64..f2e05acdf 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -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, @@ -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": diff --git a/playwright/_impl/_selectors.py b/playwright/_impl/_selectors.py index a66484d30..409b0921d 100644 --- a/playwright/_impl/_selectors.py +++ b/playwright/_impl/_selectors.py @@ -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: @@ -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: diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index 99667d85d..cc0bb862c 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -4458,7 +4458,8 @@ def get_by_role( level: typing.Optional[int] = None, name: typing.Optional[typing.Union[str, typing.Pattern[str]]] = None, pressed: typing.Optional[bool] = None, - selected: typing.Optional[bool] = None + selected: typing.Optional[bool] = None, + exact: typing.Optional[bool] = None ) -> "Locator": """Frame.get_by_role @@ -4477,21 +4478,20 @@ def get_by_role( role : Union["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "directory", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"] Required aria role. checked : Union[bool, None] - An attribute that is usually set by `aria-checked` or native `` controls. Available values for - checked are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-checked` or native `` controls. Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked). disabled : Union[bool, None] - A boolean attribute that is usually set by `aria-disabled` or `disabled`. + An attribute that is usually set by `aria-disabled` or `disabled`. > NOTE: Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about [`aria-disabled`](https://www.w3.org/TR/wai-aria-1.2/#aria-disabled). expanded : Union[bool, None] - A boolean attribute that is usually set by `aria-expanded`. + An attribute that is usually set by `aria-expanded`. Learn more about [`aria-expanded`](https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). include_hidden : Union[bool, None] - A boolean attribute that controls whether hidden elements are matched. By default, only non-hidden elements, as + Option that controls whether hidden elements are matched. By default, only non-hidden elements, as [defined by ARIA](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion), are matched by role selector. Learn more about [`aria-hidden`](https://www.w3.org/TR/wai-aria-1.2/#aria-hidden). @@ -4501,17 +4501,21 @@ def get_by_role( Learn more about [`aria-level`](https://www.w3.org/TR/wai-aria-1.2/#aria-level). name : Union[Pattern[str], str, None] - A string attribute that matches [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). + Option to match the [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). By default, matching is + case-insensitive and searches for a substring, use `exact` to control this behavior. Learn more about [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). pressed : Union[bool, None] - An attribute that is usually set by `aria-pressed`. Available values for pressed are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-pressed`. Learn more about [`aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed). selected : Union[bool, None] - A boolean attribute that is usually set by `aria-selected`. + An attribute that is usually set by `aria-selected`. Learn more about [`aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected). + exact : Union[bool, None] + Whether `name` is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when `name` is a regular + expression. Note that exact match still trims whitespace. Returns ------- @@ -4529,6 +4533,7 @@ def get_by_role( name=name, pressed=pressed, selected=selected, + exact=exact, ) ) @@ -5793,7 +5798,8 @@ def get_by_role( level: typing.Optional[int] = None, name: typing.Optional[typing.Union[str, typing.Pattern[str]]] = None, pressed: typing.Optional[bool] = None, - selected: typing.Optional[bool] = None + selected: typing.Optional[bool] = None, + exact: typing.Optional[bool] = None ) -> "Locator": """FrameLocator.get_by_role @@ -5812,21 +5818,20 @@ def get_by_role( role : Union["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "directory", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"] Required aria role. checked : Union[bool, None] - An attribute that is usually set by `aria-checked` or native `` controls. Available values for - checked are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-checked` or native `` controls. Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked). disabled : Union[bool, None] - A boolean attribute that is usually set by `aria-disabled` or `disabled`. + An attribute that is usually set by `aria-disabled` or `disabled`. > NOTE: Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about [`aria-disabled`](https://www.w3.org/TR/wai-aria-1.2/#aria-disabled). expanded : Union[bool, None] - A boolean attribute that is usually set by `aria-expanded`. + An attribute that is usually set by `aria-expanded`. Learn more about [`aria-expanded`](https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). include_hidden : Union[bool, None] - A boolean attribute that controls whether hidden elements are matched. By default, only non-hidden elements, as + Option that controls whether hidden elements are matched. By default, only non-hidden elements, as [defined by ARIA](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion), are matched by role selector. Learn more about [`aria-hidden`](https://www.w3.org/TR/wai-aria-1.2/#aria-hidden). @@ -5836,17 +5841,21 @@ def get_by_role( Learn more about [`aria-level`](https://www.w3.org/TR/wai-aria-1.2/#aria-level). name : Union[Pattern[str], str, None] - A string attribute that matches [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). + Option to match the [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). By default, matching is + case-insensitive and searches for a substring, use `exact` to control this behavior. Learn more about [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). pressed : Union[bool, None] - An attribute that is usually set by `aria-pressed`. Available values for pressed are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-pressed`. Learn more about [`aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed). selected : Union[bool, None] - A boolean attribute that is usually set by `aria-selected`. + An attribute that is usually set by `aria-selected`. Learn more about [`aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected). + exact : Union[bool, None] + Whether `name` is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when `name` is a regular + expression. Note that exact match still trims whitespace. Returns ------- @@ -5864,6 +5873,7 @@ def get_by_role( name=name, pressed=pressed, selected=selected, + exact=exact, ) ) @@ -9346,7 +9356,8 @@ def get_by_role( level: typing.Optional[int] = None, name: typing.Optional[typing.Union[str, typing.Pattern[str]]] = None, pressed: typing.Optional[bool] = None, - selected: typing.Optional[bool] = None + selected: typing.Optional[bool] = None, + exact: typing.Optional[bool] = None ) -> "Locator": """Page.get_by_role @@ -9365,21 +9376,20 @@ def get_by_role( role : Union["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "directory", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"] Required aria role. checked : Union[bool, None] - An attribute that is usually set by `aria-checked` or native `` controls. Available values for - checked are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-checked` or native `` controls. Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked). disabled : Union[bool, None] - A boolean attribute that is usually set by `aria-disabled` or `disabled`. + An attribute that is usually set by `aria-disabled` or `disabled`. > NOTE: Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about [`aria-disabled`](https://www.w3.org/TR/wai-aria-1.2/#aria-disabled). expanded : Union[bool, None] - A boolean attribute that is usually set by `aria-expanded`. + An attribute that is usually set by `aria-expanded`. Learn more about [`aria-expanded`](https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). include_hidden : Union[bool, None] - A boolean attribute that controls whether hidden elements are matched. By default, only non-hidden elements, as + Option that controls whether hidden elements are matched. By default, only non-hidden elements, as [defined by ARIA](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion), are matched by role selector. Learn more about [`aria-hidden`](https://www.w3.org/TR/wai-aria-1.2/#aria-hidden). @@ -9389,17 +9399,21 @@ def get_by_role( Learn more about [`aria-level`](https://www.w3.org/TR/wai-aria-1.2/#aria-level). name : Union[Pattern[str], str, None] - A string attribute that matches [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). + Option to match the [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). By default, matching is + case-insensitive and searches for a substring, use `exact` to control this behavior. Learn more about [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). pressed : Union[bool, None] - An attribute that is usually set by `aria-pressed`. Available values for pressed are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-pressed`. Learn more about [`aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed). selected : Union[bool, None] - A boolean attribute that is usually set by `aria-selected`. + An attribute that is usually set by `aria-selected`. Learn more about [`aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected). + exact : Union[bool, None] + Whether `name` is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when `name` is a regular + expression. Note that exact match still trims whitespace. Returns ------- @@ -9417,6 +9431,7 @@ def get_by_role( name=name, pressed=pressed, selected=selected, + exact=exact, ) ) @@ -14161,7 +14176,8 @@ def get_by_role( level: typing.Optional[int] = None, name: typing.Optional[typing.Union[str, typing.Pattern[str]]] = None, pressed: typing.Optional[bool] = None, - selected: typing.Optional[bool] = None + selected: typing.Optional[bool] = None, + exact: typing.Optional[bool] = None ) -> "Locator": """Locator.get_by_role @@ -14180,21 +14196,20 @@ def get_by_role( role : Union["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "directory", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"] Required aria role. checked : Union[bool, None] - An attribute that is usually set by `aria-checked` or native `` controls. Available values for - checked are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-checked` or native `` controls. Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked). disabled : Union[bool, None] - A boolean attribute that is usually set by `aria-disabled` or `disabled`. + An attribute that is usually set by `aria-disabled` or `disabled`. > NOTE: Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about [`aria-disabled`](https://www.w3.org/TR/wai-aria-1.2/#aria-disabled). expanded : Union[bool, None] - A boolean attribute that is usually set by `aria-expanded`. + An attribute that is usually set by `aria-expanded`. Learn more about [`aria-expanded`](https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). include_hidden : Union[bool, None] - A boolean attribute that controls whether hidden elements are matched. By default, only non-hidden elements, as + Option that controls whether hidden elements are matched. By default, only non-hidden elements, as [defined by ARIA](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion), are matched by role selector. Learn more about [`aria-hidden`](https://www.w3.org/TR/wai-aria-1.2/#aria-hidden). @@ -14204,17 +14219,21 @@ def get_by_role( Learn more about [`aria-level`](https://www.w3.org/TR/wai-aria-1.2/#aria-level). name : Union[Pattern[str], str, None] - A string attribute that matches [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). + Option to match the [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). By default, matching is + case-insensitive and searches for a substring, use `exact` to control this behavior. Learn more about [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). pressed : Union[bool, None] - An attribute that is usually set by `aria-pressed`. Available values for pressed are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-pressed`. Learn more about [`aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed). selected : Union[bool, None] - A boolean attribute that is usually set by `aria-selected`. + An attribute that is usually set by `aria-selected`. Learn more about [`aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected). + exact : Union[bool, None] + Whether `name` is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when `name` is a regular + expression. Note that exact match still trims whitespace. Returns ------- @@ -14232,6 +14251,7 @@ def get_by_role( name=name, pressed=pressed, selected=selected, + exact=exact, ) ) diff --git a/playwright/sync_api/_generated.py b/playwright/sync_api/_generated.py index 4a8d5bf71..221f0b4ad 100644 --- a/playwright/sync_api/_generated.py +++ b/playwright/sync_api/_generated.py @@ -4539,7 +4539,8 @@ def get_by_role( level: typing.Optional[int] = None, name: typing.Optional[typing.Union[str, typing.Pattern[str]]] = None, pressed: typing.Optional[bool] = None, - selected: typing.Optional[bool] = None + selected: typing.Optional[bool] = None, + exact: typing.Optional[bool] = None ) -> "Locator": """Frame.get_by_role @@ -4558,21 +4559,20 @@ def get_by_role( role : Union["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "directory", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"] Required aria role. checked : Union[bool, None] - An attribute that is usually set by `aria-checked` or native `` controls. Available values for - checked are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-checked` or native `` controls. Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked). disabled : Union[bool, None] - A boolean attribute that is usually set by `aria-disabled` or `disabled`. + An attribute that is usually set by `aria-disabled` or `disabled`. > NOTE: Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about [`aria-disabled`](https://www.w3.org/TR/wai-aria-1.2/#aria-disabled). expanded : Union[bool, None] - A boolean attribute that is usually set by `aria-expanded`. + An attribute that is usually set by `aria-expanded`. Learn more about [`aria-expanded`](https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). include_hidden : Union[bool, None] - A boolean attribute that controls whether hidden elements are matched. By default, only non-hidden elements, as + Option that controls whether hidden elements are matched. By default, only non-hidden elements, as [defined by ARIA](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion), are matched by role selector. Learn more about [`aria-hidden`](https://www.w3.org/TR/wai-aria-1.2/#aria-hidden). @@ -4582,17 +4582,21 @@ def get_by_role( Learn more about [`aria-level`](https://www.w3.org/TR/wai-aria-1.2/#aria-level). name : Union[Pattern[str], str, None] - A string attribute that matches [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). + Option to match the [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). By default, matching is + case-insensitive and searches for a substring, use `exact` to control this behavior. Learn more about [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). pressed : Union[bool, None] - An attribute that is usually set by `aria-pressed`. Available values for pressed are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-pressed`. Learn more about [`aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed). selected : Union[bool, None] - A boolean attribute that is usually set by `aria-selected`. + An attribute that is usually set by `aria-selected`. Learn more about [`aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected). + exact : Union[bool, None] + Whether `name` is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when `name` is a regular + expression. Note that exact match still trims whitespace. Returns ------- @@ -4610,6 +4614,7 @@ def get_by_role( name=name, pressed=pressed, selected=selected, + exact=exact, ) ) @@ -5901,7 +5906,8 @@ def get_by_role( level: typing.Optional[int] = None, name: typing.Optional[typing.Union[str, typing.Pattern[str]]] = None, pressed: typing.Optional[bool] = None, - selected: typing.Optional[bool] = None + selected: typing.Optional[bool] = None, + exact: typing.Optional[bool] = None ) -> "Locator": """FrameLocator.get_by_role @@ -5920,21 +5926,20 @@ def get_by_role( role : Union["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "directory", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"] Required aria role. checked : Union[bool, None] - An attribute that is usually set by `aria-checked` or native `` controls. Available values for - checked are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-checked` or native `` controls. Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked). disabled : Union[bool, None] - A boolean attribute that is usually set by `aria-disabled` or `disabled`. + An attribute that is usually set by `aria-disabled` or `disabled`. > NOTE: Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about [`aria-disabled`](https://www.w3.org/TR/wai-aria-1.2/#aria-disabled). expanded : Union[bool, None] - A boolean attribute that is usually set by `aria-expanded`. + An attribute that is usually set by `aria-expanded`. Learn more about [`aria-expanded`](https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). include_hidden : Union[bool, None] - A boolean attribute that controls whether hidden elements are matched. By default, only non-hidden elements, as + Option that controls whether hidden elements are matched. By default, only non-hidden elements, as [defined by ARIA](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion), are matched by role selector. Learn more about [`aria-hidden`](https://www.w3.org/TR/wai-aria-1.2/#aria-hidden). @@ -5944,17 +5949,21 @@ def get_by_role( Learn more about [`aria-level`](https://www.w3.org/TR/wai-aria-1.2/#aria-level). name : Union[Pattern[str], str, None] - A string attribute that matches [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). + Option to match the [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). By default, matching is + case-insensitive and searches for a substring, use `exact` to control this behavior. Learn more about [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). pressed : Union[bool, None] - An attribute that is usually set by `aria-pressed`. Available values for pressed are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-pressed`. Learn more about [`aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed). selected : Union[bool, None] - A boolean attribute that is usually set by `aria-selected`. + An attribute that is usually set by `aria-selected`. Learn more about [`aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected). + exact : Union[bool, None] + Whether `name` is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when `name` is a regular + expression. Note that exact match still trims whitespace. Returns ------- @@ -5972,6 +5981,7 @@ def get_by_role( name=name, pressed=pressed, selected=selected, + exact=exact, ) ) @@ -9394,7 +9404,8 @@ def get_by_role( level: typing.Optional[int] = None, name: typing.Optional[typing.Union[str, typing.Pattern[str]]] = None, pressed: typing.Optional[bool] = None, - selected: typing.Optional[bool] = None + selected: typing.Optional[bool] = None, + exact: typing.Optional[bool] = None ) -> "Locator": """Page.get_by_role @@ -9413,21 +9424,20 @@ def get_by_role( role : Union["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "directory", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"] Required aria role. checked : Union[bool, None] - An attribute that is usually set by `aria-checked` or native `` controls. Available values for - checked are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-checked` or native `` controls. Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked). disabled : Union[bool, None] - A boolean attribute that is usually set by `aria-disabled` or `disabled`. + An attribute that is usually set by `aria-disabled` or `disabled`. > NOTE: Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about [`aria-disabled`](https://www.w3.org/TR/wai-aria-1.2/#aria-disabled). expanded : Union[bool, None] - A boolean attribute that is usually set by `aria-expanded`. + An attribute that is usually set by `aria-expanded`. Learn more about [`aria-expanded`](https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). include_hidden : Union[bool, None] - A boolean attribute that controls whether hidden elements are matched. By default, only non-hidden elements, as + Option that controls whether hidden elements are matched. By default, only non-hidden elements, as [defined by ARIA](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion), are matched by role selector. Learn more about [`aria-hidden`](https://www.w3.org/TR/wai-aria-1.2/#aria-hidden). @@ -9437,17 +9447,21 @@ def get_by_role( Learn more about [`aria-level`](https://www.w3.org/TR/wai-aria-1.2/#aria-level). name : Union[Pattern[str], str, None] - A string attribute that matches [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). + Option to match the [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). By default, matching is + case-insensitive and searches for a substring, use `exact` to control this behavior. Learn more about [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). pressed : Union[bool, None] - An attribute that is usually set by `aria-pressed`. Available values for pressed are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-pressed`. Learn more about [`aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed). selected : Union[bool, None] - A boolean attribute that is usually set by `aria-selected`. + An attribute that is usually set by `aria-selected`. Learn more about [`aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected). + exact : Union[bool, None] + Whether `name` is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when `name` is a regular + expression. Note that exact match still trims whitespace. Returns ------- @@ -9465,6 +9479,7 @@ def get_by_role( name=name, pressed=pressed, selected=selected, + exact=exact, ) ) @@ -14230,7 +14245,8 @@ def get_by_role( level: typing.Optional[int] = None, name: typing.Optional[typing.Union[str, typing.Pattern[str]]] = None, pressed: typing.Optional[bool] = None, - selected: typing.Optional[bool] = None + selected: typing.Optional[bool] = None, + exact: typing.Optional[bool] = None ) -> "Locator": """Locator.get_by_role @@ -14249,21 +14265,20 @@ def get_by_role( role : Union["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "directory", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"] Required aria role. checked : Union[bool, None] - An attribute that is usually set by `aria-checked` or native `` controls. Available values for - checked are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-checked` or native `` controls. Learn more about [`aria-checked`](https://www.w3.org/TR/wai-aria-1.2/#aria-checked). disabled : Union[bool, None] - A boolean attribute that is usually set by `aria-disabled` or `disabled`. + An attribute that is usually set by `aria-disabled` or `disabled`. > NOTE: Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about [`aria-disabled`](https://www.w3.org/TR/wai-aria-1.2/#aria-disabled). expanded : Union[bool, None] - A boolean attribute that is usually set by `aria-expanded`. + An attribute that is usually set by `aria-expanded`. Learn more about [`aria-expanded`](https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). include_hidden : Union[bool, None] - A boolean attribute that controls whether hidden elements are matched. By default, only non-hidden elements, as + Option that controls whether hidden elements are matched. By default, only non-hidden elements, as [defined by ARIA](https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion), are matched by role selector. Learn more about [`aria-hidden`](https://www.w3.org/TR/wai-aria-1.2/#aria-hidden). @@ -14273,17 +14288,21 @@ def get_by_role( Learn more about [`aria-level`](https://www.w3.org/TR/wai-aria-1.2/#aria-level). name : Union[Pattern[str], str, None] - A string attribute that matches [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). + Option to match the [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). By default, matching is + case-insensitive and searches for a substring, use `exact` to control this behavior. Learn more about [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). pressed : Union[bool, None] - An attribute that is usually set by `aria-pressed`. Available values for pressed are `true`, `false` and `"mixed"`. + An attribute that is usually set by `aria-pressed`. Learn more about [`aria-pressed`](https://www.w3.org/TR/wai-aria-1.2/#aria-pressed). selected : Union[bool, None] - A boolean attribute that is usually set by `aria-selected`. + An attribute that is usually set by `aria-selected`. Learn more about [`aria-selected`](https://www.w3.org/TR/wai-aria-1.2/#aria-selected). + exact : Union[bool, None] + Whether `name` is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when `name` is a regular + expression. Note that exact match still trims whitespace. Returns ------- @@ -14301,6 +14320,7 @@ def get_by_role( name=name, pressed=pressed, selected=selected, + exact=exact, ) ) diff --git a/setup.py b/setup.py index 5f6d82c91..bc06f4691 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ InWheel = None from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand -driver_version = "1.28.0-alpha-nov-11-2022" +driver_version = "1.28.0-beta-1668538774000" def extractall(zip: zipfile.ZipFile, path: str) -> None: diff --git a/tests/async/test_selector_generator.py b/tests/async/test_selector_generator.py new file mode 100644 index 000000000..c03e575d3 --- /dev/null +++ b/tests/async/test_selector_generator.py @@ -0,0 +1,47 @@ +# Copyright (c) Microsoft Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest + +from playwright.async_api import Error, Page, Playwright + + +async def test_should_use_data_test_id_in_strict_errors( + page: Page, playwright: Playwright +) -> None: + playwright.selectors.set_test_id_attribute("data-custom-id") + await page.set_content( + """ +
+
+
+
+
+
+
+
+
+
+
+
+
+ """ + ) + with pytest.raises(Error) as exc_info: + await page.locator(".foo").hover(timeout=200) + assert "strict mode violation" in exc_info.value.message + assert '
None: + await page.set_content( + """ + issues 123 + he llo 56 + + """ + ) + assert await page.get_by_role("button").evaluate_all( + "els => els.map(e => e.outerHTML)" + ) == [ + "", + ] + assert await page.get_by_role("link").evaluate_all( + "els => els.map(e => e.outerHTML)" + ) == [ + """issues 123""", + """he llo 56""", + ] + + assert await page.get_by_role("link", name="issues 123").evaluate_all( + "els => els.map(e => e.outerHTML)" + ) == [ + """issues 123""", + ] + assert await page.get_by_role("link", name="sues").evaluate_all( + "els => els.map(e => e.outerHTML)" + ) == [ + """issues 123""", + ] + assert await page.get_by_role("link", name=" he \n llo ").evaluate_all( + "els => els.map(e => e.outerHTML)" + ) == [ + """he llo 56""", + ] + assert ( + await page.get_by_role("button", name="issues").evaluate_all( + "els => els.map(e => e.outerHTML)" + ) + == [] + ) + + assert ( + await page.get_by_role("link", name="sues", exact=True).evaluate_all( + "els => els.map(e => e.outerHTML)" + ) + == [] + ) + assert await page.get_by_role( + "link", name=" he \n llo 56 ", exact=True + ).evaluate_all("els => els.map(e => e.outerHTML)") == [ + """he llo 56""", + ]