From 97c64908216aec0afe9d6a9a0277fecebc3b2ae3 Mon Sep 17 00:00:00 2001 From: Ross Wollman Date: Thu, 12 May 2022 21:00:56 -0700 Subject: [PATCH] chore: remove layout locators, roll to 1.22.0 (#1300) Partial revert of ed13a53281bc213e1a4341c50d47fbc65670288f Ports the following changes: - [x] https://github.com/microsoft/playwright/commit/0e2855348cba314de3484364eb926626ca97fbd2 (feat(locators): remove layout locators (#14129)) --- playwright/_impl/_frame.py | 22 +-- playwright/_impl/_locator.py | 58 +------- playwright/_impl/_page.py | 16 +- playwright/async_api/_generated.py | 231 ++--------------------------- playwright/sync_api/_generated.py | 231 ++--------------------------- setup.py | 2 +- tests/async/test_locators.py | 14 +- tests/async/test_queryselector.py | 192 ------------------------ 8 files changed, 35 insertions(+), 731 deletions(-) diff --git a/playwright/_impl/_frame.py b/playwright/_impl/_frame.py index 0ace5023d..471ea7dcb 100644 --- a/playwright/_impl/_frame.py +++ b/playwright/_impl/_frame.py @@ -499,27 +499,9 @@ async def fill( await self._channel.send("fill", locals_to_params(locals())) def locator( - self, - selector: str, - has_text: Union[str, Pattern] = None, - has: Locator = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None, + self, selector: str, has_text: Union[str, Pattern] = None, has: Locator = None ) -> Locator: - return Locator( - self, - selector, - has_text=has_text, - has=has, - left_of=left_of, - right_of=right_of, - above=above, - below=below, - near=near, - ) + return Locator(self, selector, has_text=has_text, has=has) def frame_locator(self, selector: str) -> FrameLocator: return FrameLocator(self, selector) diff --git a/playwright/_impl/_locator.py b/playwright/_impl/_locator.py index faef55f60..01661ba67 100644 --- a/playwright/_impl/_locator.py +++ b/playwright/_impl/_locator.py @@ -26,7 +26,6 @@ Pattern, TypeVar, Union, - cast, ) from playwright._impl._api_structures import ( @@ -67,13 +66,7 @@ def __init__( selector: str, has_text: Union[str, Pattern] = None, has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None, ) -> None: - _params = locals() self._frame = frame self._selector = selector self._loop = frame._loop @@ -88,18 +81,10 @@ def __init__( escaped = escape_with_quotes(has_text, '"') self._selector += f" >> :scope:has-text({escaped})" - for inner in ["has", "left_of", "right_of", "above", "below", "near"]: - locator: Optional["Locator"] = cast("Locator", _params.get(inner)) - if not locator: - continue - if locator._frame != frame: - raise Error(f'Inner "{inner}" locator must belong to the same frame.') - engine_name = inner - if engine_name == "left_of": - engine_name = "left-of" - elif engine_name == "right_of": - engine_name = "right-of" - self._selector += f" >> {engine_name}=" + json.dumps(locator._selector) + if has: + if has._frame != frame: + raise Error('Inner "has" locator must belong to the same frame.') + self._selector += " >> has=" + json.dumps(has._selector) def __repr__(self) -> str: return f"" @@ -215,22 +200,12 @@ def locator( selector: str, has_text: Union[str, Pattern] = None, has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None, ) -> "Locator": return Locator( self._frame, f"{self._selector} >> {selector}", has_text=has_text, has=has, - left_of=left_of, - right_of=right_of, - above=above, - below=below, - near=near, ) def frame_locator(self, selector: str) -> "FrameLocator": @@ -265,22 +240,12 @@ def filter( self, has_text: Union[str, Pattern] = None, has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None, ) -> "Locator": return Locator( self._frame, self._selector, has_text=has_text, has=has, - left_of=left_of, - right_of=right_of, - above=above, - below=below, - near=near, ) async def focus(self, timeout: float = None) -> None: @@ -612,26 +577,13 @@ def __init__(self, frame: "Frame", frame_selector: str) -> None: self._frame_selector = frame_selector def locator( - self, - selector: str, - has_text: Union[str, Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None, + self, selector: str, has_text: Union[str, Pattern] = None, has: "Locator" = None ) -> Locator: return Locator( self._frame, f"{self._frame_selector} >> control=enter-frame >> {selector}", has_text=has_text, has=has, - left_of=left_of, - right_of=right_of, - above=above, - below=below, - near=near, ) def frame_locator(self, selector: str) -> "FrameLocator": diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index 2c182e23e..98916923a 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -712,22 +712,8 @@ def locator( selector: str, has_text: Union[str, Pattern] = None, has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None, ) -> "Locator": - return self._main_frame.locator( - selector, - has_text=has_text, - has=has, - left_of=left_of, - right_of=right_of, - above=above, - below=below, - near=near, - ) + return self._main_frame.locator(selector, has_text=has_text, has=has) def frame_locator(self, selector: str) -> "FrameLocator": return self.main_frame.frame_locator(selector) diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index e7ffcd5d9..51cab5cc7 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -4356,12 +4356,7 @@ def locator( selector: str, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """Frame.locator @@ -4383,36 +4378,6 @@ def locator( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -4422,14 +4387,7 @@ def locator( return mapping.from_impl( self._impl_obj.locator( - selector=selector, - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, + selector=selector, has_text=has_text, has=has._impl_obj if has else None ) ) @@ -5384,12 +5342,7 @@ def locator( selector: str, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """FrameLocator.locator @@ -5407,36 +5360,6 @@ def locator( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -5446,14 +5369,7 @@ def locator( return mapping.from_impl( self._impl_obj.locator( - selector=selector, - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, + selector=selector, has_text=has_text, has=has._impl_obj if has else None ) ) @@ -8640,12 +8556,7 @@ def locator( selector: str, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """Page.locator @@ -8669,36 +8580,6 @@ def locator( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -8708,14 +8589,7 @@ def locator( return mapping.from_impl( self._impl_obj.locator( - selector=selector, - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, + selector=selector, has_text=has_text, has=has._impl_obj if has else None ) ) @@ -13029,12 +12903,7 @@ def locator( selector: str, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """Locator.locator @@ -13053,36 +12922,6 @@ def locator( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -13092,14 +12931,7 @@ def locator( return mapping.from_impl( self._impl_obj.locator( - selector=selector, - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, + selector=selector, has_text=has_text, has=has._impl_obj if has else None ) ) @@ -13185,12 +13017,7 @@ def filter( self, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """Locator.filter @@ -13206,36 +13033,6 @@ def filter( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -13244,15 +13041,7 @@ def filter( """ return mapping.from_impl( - self._impl_obj.filter( - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, - ) + self._impl_obj.filter(has_text=has_text, has=has._impl_obj if has else None) ) async def focus(self, *, timeout: float = None) -> NoneType: diff --git a/playwright/sync_api/_generated.py b/playwright/sync_api/_generated.py index 0dc0ac7a4..564495fe3 100644 --- a/playwright/sync_api/_generated.py +++ b/playwright/sync_api/_generated.py @@ -4300,12 +4300,7 @@ def locator( selector: str, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """Frame.locator @@ -4327,36 +4322,6 @@ def locator( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -4366,14 +4331,7 @@ def locator( return mapping.from_impl( self._impl_obj.locator( - selector=selector, - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, + selector=selector, has_text=has_text, has=has._impl_obj if has else None ) ) @@ -5325,12 +5283,7 @@ def locator( selector: str, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """FrameLocator.locator @@ -5348,36 +5301,6 @@ def locator( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -5387,14 +5310,7 @@ def locator( return mapping.from_impl( self._impl_obj.locator( - selector=selector, - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, + selector=selector, has_text=has_text, has=has._impl_obj if has else None ) ) @@ -8449,12 +8365,7 @@ def locator( selector: str, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """Page.locator @@ -8478,36 +8389,6 @@ def locator( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -8517,14 +8398,7 @@ def locator( return mapping.from_impl( self._impl_obj.locator( - selector=selector, - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, + selector=selector, has_text=has_text, has=has._impl_obj if has else None ) ) @@ -12763,12 +12637,7 @@ def locator( selector: str, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """Locator.locator @@ -12787,36 +12656,6 @@ def locator( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -12826,14 +12665,7 @@ def locator( return mapping.from_impl( self._impl_obj.locator( - selector=selector, - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, + selector=selector, has_text=has_text, has=has._impl_obj if has else None ) ) @@ -12917,12 +12749,7 @@ def filter( self, *, has_text: typing.Union[str, typing.Pattern] = None, - has: "Locator" = None, - left_of: "Locator" = None, - right_of: "Locator" = None, - above: "Locator" = None, - below: "Locator" = None, - near: "Locator" = None + has: "Locator" = None ) -> "Locator": """Locator.filter @@ -12938,36 +12765,6 @@ def filter( Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that has `text=Playwright` matches `
Playwright
`. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - left_of : Union[Locator, NoneType] - Matches elements that are to the left of any element matching the inner locator, at any vertical position. Inner locator - is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - right_of : Union[Locator, NoneType] - Matches elements that are to the right of any element matching the inner locator, at any vertical position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - above : Union[Locator, NoneType] - Matches elements that are above any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - below : Union[Locator, NoneType] - Matches elements that are below any of the elements matching the inner locator, at any horizontal position. Inner - locator is queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. - near : Union[Locator, NoneType] - Matches elements that are near (<= 50 css pixels) any of the elements matching the inner locator. Inner locator is - queried against the same root as the outer one. More details in - [layout selectors](../selectors.md#selecting-elements-based-on-layout) guide. - Note that outer and inner locators must belong to the same frame. Inner locator must not contain `FrameLocator`s. Returns @@ -12976,15 +12773,7 @@ def filter( """ return mapping.from_impl( - self._impl_obj.filter( - has_text=has_text, - has=has._impl_obj if has else None, - left_of=left_of._impl_obj if left_of else None, - right_of=right_of._impl_obj if right_of else None, - above=above._impl_obj if above else None, - below=below._impl_obj if below else None, - near=near._impl_obj if near else None, - ) + self._impl_obj.filter(has_text=has_text, has=has._impl_obj if has else None) ) def focus(self, *, timeout: float = None) -> NoneType: diff --git a/setup.py b/setup.py index 036d91eb5..993b0cc19 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.22.0-alpha-may-11-2022" +driver_version = "1.22.0" def extractall(zip: zipfile.ZipFile, path: str) -> None: diff --git a/tests/async/test_locators.py b/tests/async/test_locators.py index 4673426a9..a5458570a 100644 --- a/tests/async/test_locators.py +++ b/tests/async/test_locators.py @@ -738,18 +738,16 @@ async def test_locator_should_support_has_locator(page: Page, server: Server) -> ).to_have_count(1) -async def test_locator_should_enforce_same_frame_for_has_and_layout_locators( +async def test_locator_should_enforce_same_frame_for_has_locator( page: Page, server: Server ) -> None: await page.goto(server.PREFIX + "/frames/two-frames.html") child = page.frames[1] - for option in ["has", "left_of", "right_of", "above", "below", "near"]: - with pytest.raises(Error) as exc_info: - page.locator("div", **{option: child.locator("span")}) - assert ( - f'Inner "{option}" locator must belong to the same frame.' - in exc_info.value.message - ) + with pytest.raises(Error) as exc_info: + page.locator("div", has=child.locator("span")) + assert ( + 'Inner "has" locator must belong to the same frame.' in exc_info.value.message + ) async def test_locator_highlight_should_work(page: Page, server: Server) -> None: diff --git a/tests/async/test_queryselector.py b/tests/async/test_queryselector.py index 2daa063f0..65e2700dd 100644 --- a/tests/async/test_queryselector.py +++ b/tests/async/test_queryselector.py @@ -242,282 +242,118 @@ async def test_should_work_with_layout_selectors(page: Page) -> None: ) assert await page.eval_on_selector("div:right-of(#id6)", "e => e.id") == "id7" - assert await page.eval_on_selector('div >> right-of="#id6"', "e => e.id") == "id7" - assert ( - await page.locator("div", right_of=page.locator("#id6")).first.evaluate( - "e => e.id" - ) - == "id7" - ) assert await page.eval_on_selector("div:right-of(#id1)", "e => e.id") == "id2" - assert await page.eval_on_selector('div >> right-of="#id1"', "e => e.id") == "id2" assert await page.eval_on_selector("div:right-of(#id3)", "e => e.id") == "id4" - assert await page.eval_on_selector('div >> right-of="#id3"', "e => e.id") == "id4" assert await page.query_selector("div:right-of(#id4)") is None - assert await page.query_selector('div >> right-of="#id4"') is None assert await page.eval_on_selector("div:right-of(#id0)", "e => e.id") == "id7" - assert await page.eval_on_selector('div >> right-of="#id0"', "e => e.id") == "id7" assert await page.eval_on_selector("div:right-of(#id8)", "e => e.id") == "id9" - assert await page.eval_on_selector('div >> right-of="#id8"', "e => e.id") == "id9" assert ( await page.eval_on_selector_all( "div:right-of(#id3)", "els => els.map(e => e.id).join(',')" ) == "id4,id2,id5,id7,id8,id9" ) - assert ( - await page.eval_on_selector_all( - 'div >> right-of="#id3"', "els => els.map(e => e.id).join(',')" - ) - == "id4,id2,id5,id7,id8,id9" - ) - assert ( - await page.locator("div", right_of=page.locator("#id3")) - .locator("span") - .evaluate_all("els => els.map(e => e.textContent).join(',')") - == "4,2,5,7,8,9" - ) assert ( await page.eval_on_selector_all( "div:right-of(#id3, 50)", "els => els.map(e => e.id).join(',')" ) == "id2,id5,id7,id8" ) - assert ( - await page.eval_on_selector_all( - 'div >> right-of="#id3",50', "els => els.map(e => e.id).join(',')" - ) - == "id2,id5,id7,id8" - ) - assert ( - await page.eval_on_selector_all( - 'div >> right-of="#id3",50 >> span', - "els => els.map(e => e.textContent).join(',')", - ) - == "2,5,7,8" - ) assert ( await page.eval_on_selector_all( "div:right-of(#id3, 49)", "els => els.map(e => e.id).join(',')" ) == "id7,id8" ) - assert ( - await page.eval_on_selector_all( - 'div >> right-of="#id3",49', "els => els.map(e => e.id).join(',')" - ) - == "id7,id8" - ) - assert ( - await page.eval_on_selector_all( - 'div >> right-of="#id3",49 >> span', - "els => els.map(e => e.textContent).join(',')", - ) - == "7,8" - ) assert await page.eval_on_selector("div:left-of(#id2)", "e => e.id") == "id1" - assert await page.eval_on_selector('div >> left-of="#id2"', "e => e.id") == "id1" - assert ( - await page.locator("div", left_of=page.locator("#id2")).first.evaluate( - "e => e.id" - ) - == "id1" - ) assert await page.query_selector("div:left-of(#id0)") is None - assert await page.query_selector('div >> left-of="#id0"') is None assert await page.eval_on_selector("div:left-of(#id5)", "e => e.id") == "id0" - assert await page.eval_on_selector('div >> left-of="#id5"', "e => e.id") == "id0" assert await page.eval_on_selector("div:left-of(#id9)", "e => e.id") == "id8" - assert await page.eval_on_selector('div >> left-of="#id9"', "e => e.id") == "id8" assert await page.eval_on_selector("div:left-of(#id4)", "e => e.id") == "id3" - assert await page.eval_on_selector('div >> left-of="#id4"', "e => e.id") == "id3" assert ( await page.eval_on_selector_all( "div:left-of(#id5)", "els => els.map(e => e.id).join(',')" ) == "id0,id7,id3,id1,id6,id8" ) - assert ( - await page.eval_on_selector_all( - 'div >> left-of="#id5"', "els => els.map(e => e.id).join(',')" - ) - == "id0,id7,id3,id1,id6,id8" - ) assert ( await page.eval_on_selector_all( "div:left-of(#id5, 3)", "els => els.map(e => e.id).join(',')" ) == "id7,id8" ) - assert ( - await page.eval_on_selector_all( - 'div >> left-of="#id5",3', "els => els.map(e => e.id).join(',')" - ) - == "id7,id8" - ) - assert ( - await page.eval_on_selector_all( - 'div >> left-of="#id5",3 >> span', - "els => els.map(e => e.textContent).join(',')", - ) - == "7,8" - ) assert await page.eval_on_selector("div:above(#id0)", "e => e.id") == "id3" - assert await page.eval_on_selector('div >> above="#id0"', "e => e.id") == "id3" - assert ( - await page.locator("div", above=page.locator("#id0")).first.evaluate( - "e => e.id" - ) - == "id3" - ) assert await page.eval_on_selector("div:above(#id5)", "e => e.id") == "id4" - assert await page.eval_on_selector('div >> above="#id5"', "e => e.id") == "id4" assert await page.eval_on_selector("div:above(#id7)", "e => e.id") == "id5" - assert await page.eval_on_selector('div >> above="#id7"', "e => e.id") == "id5" assert await page.eval_on_selector("div:above(#id8)", "e => e.id") == "id0" - assert await page.eval_on_selector('div >> above="#id8"', "e => e.id") == "id0" assert await page.eval_on_selector("div:above(#id9)", "e => e.id") == "id8" - assert await page.eval_on_selector('div >> above="#id9"', "e => e.id") == "id8" assert await page.query_selector("div:above(#id2)") is None - assert await page.query_selector('div >> above="#id2"') is None assert ( await page.eval_on_selector_all( "div:above(#id5)", "els => els.map(e => e.id).join(',')" ) == "id4,id2,id3,id1" ) - assert ( - await page.eval_on_selector_all( - 'div >> above="#id5"', "els => els.map(e => e.id).join(',')" - ) - == "id4,id2,id3,id1" - ) assert ( await page.eval_on_selector_all( "div:above(#id5, 20)", "els => els.map(e => e.id).join(',')" ) == "id4,id3" ) - assert ( - await page.eval_on_selector_all( - 'div >> above="#id5",20', "els => els.map(e => e.id).join(',')" - ) - == "id4,id3" - ) assert await page.eval_on_selector("div:below(#id4)", "e => e.id") == "id5" - assert await page.eval_on_selector('div >> below="#id4"', "e => e.id") == "id5" - assert ( - await page.locator("div", below=page.locator("#id4")).first.evaluate( - "e => e.id" - ) - == "id5" - ) assert await page.eval_on_selector("div:below(#id3)", "e => e.id") == "id0" - assert await page.eval_on_selector('div >> below="#id3"', "e => e.id") == "id0" assert await page.eval_on_selector("div:below(#id2)", "e => e.id") == "id4" - assert await page.eval_on_selector('div >> below="#id2"', "e => e.id") == "id4" assert await page.eval_on_selector("div:below(#id6)", "e => e.id") == "id8" - assert await page.eval_on_selector('div >> below="#id6"', "e => e.id") == "id8" assert await page.eval_on_selector("div:below(#id7)", "e => e.id") == "id8" - assert await page.eval_on_selector('div >> below="#id7"', "e => e.id") == "id8" assert await page.eval_on_selector("div:below(#id8)", "e => e.id") == "id9" - assert await page.eval_on_selector('div >> below="#id8"', "e => e.id") == "id9" assert await page.query_selector("div:below(#id9)") is None - assert await page.query_selector('div >> below="#id9"') is None assert ( await page.eval_on_selector_all( "div:below(#id3)", "els => els.map(e => e.id).join(',')" ) == "id0,id5,id6,id7,id8,id9" ) - assert ( - await page.eval_on_selector_all( - 'div >> below="#id3"', "els => els.map(e => e.id).join(',')" - ) - == "id0,id5,id6,id7,id8,id9" - ) assert ( await page.eval_on_selector_all( "div:below(#id3, 105)", "els => els.map(e => e.id).join(',')" ) == "id0,id5,id6,id7" ) - assert ( - await page.eval_on_selector_all( - 'div >> below="#id3" , 105', "els => els.map(e => e.id).join(',')" - ) - == "id0,id5,id6,id7" - ) assert await page.eval_on_selector("div:near(#id0)", "e => e.id") == "id3" - assert await page.eval_on_selector('div >> near="#id0"', "e => e.id") == "id3" - assert ( - await page.locator("div", near=page.locator("#id0")).first.evaluate("e => e.id") - == "id3" - ) assert ( await page.eval_on_selector_all( "div:near(#id7)", "els => els.map(e => e.id).join(',')" ) == "id0,id5,id3,id6" ) - assert ( - await page.eval_on_selector_all( - 'div >> near="#id7"', "els => els.map(e => e.id).join(',')" - ) - == "id0,id5,id3,id6" - ) assert ( await page.eval_on_selector_all( "div:near(#id0)", "els => els.map(e => e.id).join(',')" ) == "id3,id6,id7,id8,id1,id5" ) - assert ( - await page.eval_on_selector_all( - 'div >> near="#id0"', "els => els.map(e => e.id).join(',')" - ) - == "id3,id6,id7,id8,id1,id5" - ) assert ( await page.eval_on_selector_all( "div:near(#id6)", "els => els.map(e => e.id).join(',')" ) == "id0,id3,id7" ) - assert ( - await page.eval_on_selector_all( - 'div >> near="#id6"', "els => els.map(e => e.id).join(',')" - ) - == "id0,id3,id7" - ) assert ( await page.eval_on_selector_all( "div:near(#id6, 10)", "els => els.map(e => e.id).join(',')" ) == "id0" ) - assert ( - await page.eval_on_selector_all( - 'div >> near="#id6",10', "els => els.map(e => e.id).join(',')" - ) - == "id0" - ) assert ( await page.eval_on_selector_all( "div:near(#id0, 100)", "els => els.map(e => e.id).join(',')" ) == "id3,id6,id7,id8,id1,id5,id4,id2" ) - assert ( - await page.eval_on_selector_all( - 'div >> near="#id0",100', "els => els.map(e => e.id).join(',')" - ) - == "id3,id6,id7,id8,id1,id5,id4,id2" - ) assert ( await page.eval_on_selector_all( @@ -525,25 +361,9 @@ async def test_should_work_with_layout_selectors(page: Page) -> None: ) == "id7,id6" ) - assert ( - await page.eval_on_selector_all( - 'div >> below="#id5" >> above="#id8"', "els => els.map(e => e.id).join(',')" - ) - == "id7,id6" - ) assert ( await page.eval_on_selector("div:below(#id5):above(#id8)", "e => e.id") == "id7" ) - assert ( - await page.eval_on_selector('div >> below="#id5" >> above="#id8"', "e => e.id") - == "id7" - ) - assert ( - await page.locator( - "div", below=page.locator("#id5"), above=page.locator("#id8") - ).first.evaluate("e => e.id") - == "id7" - ) assert ( await page.eval_on_selector_all( @@ -559,18 +379,6 @@ async def test_should_work_with_layout_selectors(page: Page) -> None: '"near" engine expects a selector list and optional maximum distance in pixels' in exc_info.value.message ) - with pytest.raises(Error) as exc_info: - await page.query_selector("div >> left-of=abc") - assert "Malformed selector: left-of=abc" in exc_info.value.message with pytest.raises(Error) as exc_info: await page.query_selector('left-of="div"') assert '"left-of" selector cannot be first' in exc_info.value.message - with pytest.raises(Error) as exc_info: - await page.query_selector("div >> left-of=33") - assert "Malformed selector: left-of=33" in exc_info.value.message - with pytest.raises(Error) as exc_info: - await page.query_selector('div >> left-of="span","foo"') - assert 'Malformed selector: left-of="span","foo"' in exc_info.value.message - with pytest.raises(Error) as exc_info: - await page.query_selector('div >> left-of="span",3,4') - assert 'Malformed selector: left-of="span",3,4' in exc_info.value.message