Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore(roll): roll Playwright to 1.28.0-alpha-nov-2-2022 #1627

Merged
merged 5 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->107.0.5304.18<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->108.0.5359.22<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->16.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->105.0.1<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->106.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_api_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,5 @@ class FrameExpectResult(TypedDict):
"tooltip",
"tree",
"treegrid",
"treeite",
"treeitem",
]
10 changes: 8 additions & 2 deletions playwright/_impl/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async def new_context(
recordHarContent: HarContentPolicy = None,
) -> BrowserContext:
params = locals_to_params(locals())
await normalize_context_params(self._connection._is_sync, params)
await prepare_browser_context_params(params)

channel = await self._channel.send("newContext", params)
context = cast(BrowserContext, from_channel(channel))
Expand Down Expand Up @@ -219,7 +219,7 @@ async def stop_tracing(self) -> bytes:
return base64.b64decode(encoded_binary)


async def normalize_context_params(is_sync: bool, params: Dict) -> None:
async def prepare_browser_context_params(params: Dict) -> None:
if params.get("noViewport"):
del params["noViewport"]
params["noDefaultViewport"] = True
Expand All @@ -242,3 +242,9 @@ async def normalize_context_params(is_sync: bool, params: Dict) -> None:
params["storageState"] = json.loads(
(await async_readfile(storageState)).decode()
)
if params.get("colorScheme", None) is None:
params["colorScheme"] = "no-override"
if params.get("reducedMotion", None) is None:
params["reducedMotion"] = "no-override"
if params.get("forcedColors", None) is None:
params["forcedColors"] = "no-override"
4 changes: 2 additions & 2 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ViewportSize,
)
from playwright._impl._api_types import Error
from playwright._impl._browser import Browser, normalize_context_params
from playwright._impl._browser import Browser, prepare_browser_context_params
from playwright._impl._browser_context import BrowserContext
from playwright._impl._connection import (
ChannelOwner,
Expand Down Expand Up @@ -148,7 +148,7 @@ async def launch_persistent_context(
) -> BrowserContext:
userDataDir = str(Path(userDataDir)) if userDataDir else ""
params = locals_to_params(locals())
await normalize_context_params(self._connection._is_sync, params)
await prepare_browser_context_params(params)
normalize_launch_params(params)
context = cast(
BrowserContext,
Expand Down
9 changes: 9 additions & 0 deletions playwright/_impl/_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ async def hover(
modifiers: List[KeyboardModifier] = None,
position: Position = None,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
trial: bool = None,
) -> None:
Expand Down Expand Up @@ -217,6 +218,14 @@ async def type(
) -> None:
await self._channel.send("type", locals_to_params(locals()))

async def clear(
self,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
) -> None:
await self.fill("", **locals_to_params(locals()))

async def press(
self,
key: str,
Expand Down
42 changes: 32 additions & 10 deletions playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,23 @@ async def _wait_for_load_state_impl(
raise Error(
"state: expected one of (load|domcontentloaded|networkidle|commit)"
)
if state in self._load_states:
return
wait_helper = self._setup_navigation_wait_helper("wait_for_load_state", timeout)

def handle_load_state_event(actual_state: str) -> bool:
wait_helper.log(f'"{actual_state}" event fired')
return actual_state == state
if state in self._load_states:
wait_helper.log(f' not waiting, "{state}" event already fired')
# TODO: align with upstream
wait_helper._fulfill(None)
else:

wait_helper.wait_for_event(
self._event_emitter,
"loadstate",
handle_load_state_event,
)
def handle_load_state_event(actual_state: str) -> bool:
wait_helper.log(f'"{actual_state}" event fired')
return actual_state == state

wait_helper.wait_for_event(
self._event_emitter,
"loadstate",
handle_load_state_event,
)
await wait_helper.result()

async def frame_element(self) -> ElementHandle:
Expand Down Expand Up @@ -618,6 +622,7 @@ async def hover(
modifiers: List[KeyboardModifier] = None,
position: Position = None,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
strict: bool = None,
trial: bool = None,
Expand Down Expand Up @@ -789,5 +794,22 @@ async def set_checked(
trial=trial,
)

async def clear(
self,
selector: str,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
strict: bool = None,
) -> None:
await self.fill(
selector,
"",
timeout=timeout,
noWaitAfter=noWaitAfter,
force=force,
strict=strict,
)

async def _highlight(self, selector: str) -> None:
await self._channel.send("highlight", {"selector": selector})
28 changes: 22 additions & 6 deletions playwright/_impl/_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ def __init__(
self._dispatcher_fiber = frame._connection._dispatcher_fiber

if has_text:
text_selector = "text=" + escape_for_text_selector(has_text, exact=False)
self._selector += (
f" >> internal:has={json.dumps(text_selector, ensure_ascii=False)}"
)
self._selector += f" >> internal:has-text={escape_for_text_selector(has_text, exact=False)}"

if has:
if has._frame != frame:
Expand Down Expand Up @@ -200,6 +197,14 @@ async def fill(
params = locals_to_params(locals())
return await self._frame.fill(self._selector, strict=True, **params)

async def clear(
self,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
) -> None:
await self.fill("", timeout=timeout, noWaitAfter=noWaitAfter, force=force)

def locator(
self,
selector: str,
Expand Down Expand Up @@ -311,6 +316,16 @@ async def focus(self, timeout: float = None) -> None:
params = locals_to_params(locals())
return await self._frame.focus(self._selector, strict=True, **params)

async def blur(self, timeout: float = None) -> None:
await self._frame._channel.send(
"blur",
{
"selector": self._selector,
"strict": True,
**locals_to_params(locals()),
},
)

async def count(
self,
) -> int:
Expand Down Expand Up @@ -345,6 +360,7 @@ async def hover(
modifiers: List[KeyboardModifier] = None,
position: Position = None,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
trial: bool = None,
) -> None:
Expand Down Expand Up @@ -762,7 +778,7 @@ def get_by_placeholder_selector(


def get_by_text_selector(text: Union[str, Pattern[str]], exact: bool = None) -> str:
return "text=" + escape_for_text_selector(text, exact=exact)
return "internal:text=" + escape_for_text_selector(text, exact=exact)


def get_by_role_selector(
Expand Down Expand Up @@ -801,4 +817,4 @@ def get_by_role_selector(
if pressed is not None:
props.append(("pressed", str(pressed)))
props_str = "".join([f"[{t[0]}={t[1]}]" for t in props])
return f"role={role}{props_str}"
return f"internal:role={role}{props_str}"
30 changes: 29 additions & 1 deletion playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,17 @@ async def emulate_media(
reducedMotion: ReducedMotion = None,
forcedColors: ForcedColors = None,
) -> None:
await self._channel.send("emulateMedia", locals_to_params(locals()))
params = locals_to_params(locals())
params["colorScheme"] = (
"no-override" if "colorScheme" not in params else colorScheme
)
params["reducedMotion"] = (
"no-override" if "reducedMotion" not in params else reducedMotion
)
params["forcedColors"] = (
"no-override" if "forcedColors" not in params else forcedColors
)
await self._channel.send("emulateMedia", params)

async def set_viewport_size(self, viewportSize: ViewportSize) -> None:
self._viewport_size = viewportSize
Expand Down Expand Up @@ -728,6 +738,23 @@ async def fill(
) -> None:
return await self._main_frame.fill(**locals_to_params(locals()))

async def clear(
self,
selector: str,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
strict: bool = None,
) -> None:
await self.fill(
selector,
"",
timeout=timeout,
noWaitAfter=noWaitAfter,
force=force,
strict=strict,
)

def locator(
self,
selector: str,
Expand Down Expand Up @@ -822,6 +849,7 @@ async def hover(
modifiers: List[KeyboardModifier] = None,
position: Position = None,
timeout: float = None,
noWaitAfter: bool = None,
force: bool = None,
strict: bool = None,
trial: bool = None,
Expand Down
8 changes: 2 additions & 6 deletions playwright/_impl/_str_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import re
from typing import Pattern, Union

Expand Down Expand Up @@ -43,12 +44,7 @@ def escape_for_text_selector(
) -> str:
if isinstance(text, Pattern):
return f"/{text.pattern}/{escape_regex_flags(text)}"
if exact:
return '"' + text.replace('"', '\\"') + '"'
if '"' in text or ">>" in text or text[0] == "/":
suffix = "" if case_sensitive else "i"
return "/" + re.sub(r"\s+", "\\\\s+", escape_for_regex(text)) + "/" + suffix
return text
return json.dumps(text) + ("s" if exact else "i")


def escape_for_attribute_selector(value: str, exact: bool = None) -> str:
Expand Down