Skip to content

Commit 843d96e

Browse files
authored
chore(roll): roll Playwright to 1.28.0-alpha-nov-2-2022 (#1627)
1 parent cb2e94c commit 843d96e

34 files changed

+1355
-407
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H
44

55
| | Linux | macOS | Windows |
66
| :--- | :---: | :---: | :---: |
7-
| Chromium <!-- GEN:chromium-version -->107.0.5304.18<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->108.0.5359.22<!-- GEN:stop --> ||||
88
| WebKit <!-- GEN:webkit-version -->16.0<!-- GEN:stop --> ||||
9-
| Firefox <!-- GEN:firefox-version -->105.0.1<!-- GEN:stop --> ||||
9+
| Firefox <!-- GEN:firefox-version -->106.0<!-- GEN:stop --> ||||
1010

1111
## Documentation
1212

playwright/_impl/_api_structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,5 +280,5 @@ class FrameExpectResult(TypedDict):
280280
"tooltip",
281281
"tree",
282282
"treegrid",
283-
"treeite",
283+
"treeitem",
284284
]

playwright/_impl/_browser.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async def new_context(
122122
recordHarContent: HarContentPolicy = None,
123123
) -> BrowserContext:
124124
params = locals_to_params(locals())
125-
await normalize_context_params(self._connection._is_sync, params)
125+
await prepare_browser_context_params(params)
126126

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

221221

222-
async def normalize_context_params(is_sync: bool, params: Dict) -> None:
222+
async def prepare_browser_context_params(params: Dict) -> None:
223223
if params.get("noViewport"):
224224
del params["noViewport"]
225225
params["noDefaultViewport"] = True
@@ -242,3 +242,9 @@ async def normalize_context_params(is_sync: bool, params: Dict) -> None:
242242
params["storageState"] = json.loads(
243243
(await async_readfile(storageState)).decode()
244244
)
245+
if params.get("colorScheme", None) == "null":
246+
params["colorScheme"] = "no-override"
247+
if params.get("reducedMotion", None) == "null":
248+
params["reducedMotion"] = "no-override"
249+
if params.get("forcedColors", None) == "null":
250+
params["forcedColors"] = "no-override"

playwright/_impl/_browser_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
ViewportSize,
2525
)
2626
from playwright._impl._api_types import Error
27-
from playwright._impl._browser import Browser, normalize_context_params
27+
from playwright._impl._browser import Browser, prepare_browser_context_params
2828
from playwright._impl._browser_context import BrowserContext
2929
from playwright._impl._connection import (
3030
ChannelOwner,
@@ -148,7 +148,7 @@ async def launch_persistent_context(
148148
) -> BrowserContext:
149149
userDataDir = str(Path(userDataDir)) if userDataDir else ""
150150
params = locals_to_params(locals())
151-
await normalize_context_params(self._connection._is_sync, params)
151+
await prepare_browser_context_params(params)
152152
normalize_launch_params(params)
153153
context = cast(
154154
BrowserContext,

playwright/_impl/_element_handle.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ async def hover(
106106
modifiers: List[KeyboardModifier] = None,
107107
position: Position = None,
108108
timeout: float = None,
109+
noWaitAfter: bool = None,
109110
force: bool = None,
110111
trial: bool = None,
111112
) -> None:
@@ -217,6 +218,14 @@ async def type(
217218
) -> None:
218219
await self._channel.send("type", locals_to_params(locals()))
219220

221+
async def clear(
222+
self,
223+
timeout: float = None,
224+
noWaitAfter: bool = None,
225+
force: bool = None,
226+
) -> None:
227+
await self.fill("", **locals_to_params(locals()))
228+
220229
async def press(
221230
self,
222231
key: str,

playwright/_impl/_frame.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,23 @@ async def _wait_for_load_state_impl(
249249
raise Error(
250250
"state: expected one of (load|domcontentloaded|networkidle|commit)"
251251
)
252-
if state in self._load_states:
253-
return
254252
wait_helper = self._setup_navigation_wait_helper("wait_for_load_state", timeout)
255253

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

260-
wait_helper.wait_for_event(
261-
self._event_emitter,
262-
"loadstate",
263-
handle_load_state_event,
264-
)
260+
def handle_load_state_event(actual_state: str) -> bool:
261+
wait_helper.log(f'"{actual_state}" event fired')
262+
return actual_state == state
263+
264+
wait_helper.wait_for_event(
265+
self._event_emitter,
266+
"loadstate",
267+
handle_load_state_event,
268+
)
265269
await wait_helper.result()
266270

267271
async def frame_element(self) -> ElementHandle:
@@ -618,6 +622,7 @@ async def hover(
618622
modifiers: List[KeyboardModifier] = None,
619623
position: Position = None,
620624
timeout: float = None,
625+
noWaitAfter: bool = None,
621626
force: bool = None,
622627
strict: bool = None,
623628
trial: bool = None,
@@ -789,5 +794,22 @@ async def set_checked(
789794
trial=trial,
790795
)
791796

797+
async def clear(
798+
self,
799+
selector: str,
800+
timeout: float = None,
801+
noWaitAfter: bool = None,
802+
force: bool = None,
803+
strict: bool = None,
804+
) -> None:
805+
await self.fill(
806+
selector,
807+
"",
808+
timeout=timeout,
809+
noWaitAfter=noWaitAfter,
810+
force=force,
811+
strict=strict,
812+
)
813+
792814
async def _highlight(self, selector: str) -> None:
793815
await self._channel.send("highlight", {"selector": selector})

playwright/_impl/_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
Callable[["Route"], Any], Callable[["Route", "Request"], Any]
6161
]
6262

63-
ColorScheme = Literal["dark", "light", "no-preference"]
64-
ForcedColors = Literal["active", "none"]
65-
ReducedMotion = Literal["no-preference", "reduce"]
63+
ColorScheme = Literal["dark", "light", "no-preference", "null"]
64+
ForcedColors = Literal["active", "none", "null"]
65+
ReducedMotion = Literal["no-preference", "null", "reduce"]
6666
DocumentLoadState = Literal["commit", "domcontentloaded", "load", "networkidle"]
6767
KeyboardModifier = Literal["Alt", "Control", "Meta", "Shift"]
6868
MouseButton = Literal["left", "middle", "right"]

playwright/_impl/_locator.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ def __init__(
7979
self._dispatcher_fiber = frame._connection._dispatcher_fiber
8080

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

8784
if has:
8885
if has._frame != frame:
@@ -200,6 +197,14 @@ async def fill(
200197
params = locals_to_params(locals())
201198
return await self._frame.fill(self._selector, strict=True, **params)
202199

200+
async def clear(
201+
self,
202+
timeout: float = None,
203+
noWaitAfter: bool = None,
204+
force: bool = None,
205+
) -> None:
206+
await self.fill("", timeout=timeout, noWaitAfter=noWaitAfter, force=force)
207+
203208
def locator(
204209
self,
205210
selector: str,
@@ -311,6 +316,16 @@ async def focus(self, timeout: float = None) -> None:
311316
params = locals_to_params(locals())
312317
return await self._frame.focus(self._selector, strict=True, **params)
313318

319+
async def blur(self, timeout: float = None) -> None:
320+
await self._frame._channel.send(
321+
"blur",
322+
{
323+
"selector": self._selector,
324+
"strict": True,
325+
**locals_to_params(locals()),
326+
},
327+
)
328+
314329
async def count(
315330
self,
316331
) -> int:
@@ -345,6 +360,7 @@ async def hover(
345360
modifiers: List[KeyboardModifier] = None,
346361
position: Position = None,
347362
timeout: float = None,
363+
noWaitAfter: bool = None,
348364
force: bool = None,
349365
trial: bool = None,
350366
) -> None:
@@ -762,7 +778,7 @@ def get_by_placeholder_selector(
762778

763779

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

767783

768784
def get_by_role_selector(
@@ -801,4 +817,4 @@ def get_by_role_selector(
801817
if pressed is not None:
802818
props.append(("pressed", str(pressed)))
803819
props_str = "".join([f"[{t[0]}={t[1]}]" for t in props])
804-
return f"role={role}{props_str}"
820+
return f"internal:role={role}{props_str}"

playwright/_impl/_page.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,20 @@ async def emulate_media(
550550
reducedMotion: ReducedMotion = None,
551551
forcedColors: ForcedColors = None,
552552
) -> None:
553-
await self._channel.send("emulateMedia", locals_to_params(locals()))
553+
params = locals_to_params(locals())
554+
if "colorScheme" in params:
555+
params["colorScheme"] = (
556+
"no-override" if params["colorScheme"] == "null" else colorScheme
557+
)
558+
if "reducedMotion" in params:
559+
params["reducedMotion"] = (
560+
"no-override" if params["reducedMotion"] == "null" else reducedMotion
561+
)
562+
if "forcedColors" in params:
563+
params["forcedColors"] = (
564+
"no-override" if params["forcedColors"] == "null" else forcedColors
565+
)
566+
await self._channel.send("emulateMedia", params)
554567

555568
async def set_viewport_size(self, viewportSize: ViewportSize) -> None:
556569
self._viewport_size = viewportSize
@@ -728,6 +741,23 @@ async def fill(
728741
) -> None:
729742
return await self._main_frame.fill(**locals_to_params(locals()))
730743

744+
async def clear(
745+
self,
746+
selector: str,
747+
timeout: float = None,
748+
noWaitAfter: bool = None,
749+
force: bool = None,
750+
strict: bool = None,
751+
) -> None:
752+
await self.fill(
753+
selector,
754+
"",
755+
timeout=timeout,
756+
noWaitAfter=noWaitAfter,
757+
force=force,
758+
strict=strict,
759+
)
760+
731761
def locator(
732762
self,
733763
selector: str,
@@ -822,6 +852,7 @@ async def hover(
822852
modifiers: List[KeyboardModifier] = None,
823853
position: Position = None,
824854
timeout: float = None,
855+
noWaitAfter: bool = None,
825856
force: bool = None,
826857
strict: bool = None,
827858
trial: bool = None,

playwright/_impl/_str_utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import json
1516
import re
1617
from typing import Pattern, Union
1718

@@ -43,12 +44,7 @@ def escape_for_text_selector(
4344
) -> str:
4445
if isinstance(text, Pattern):
4546
return f"/{text.pattern}/{escape_regex_flags(text)}"
46-
if exact:
47-
return '"' + text.replace('"', '\\"') + '"'
48-
if '"' in text or ">>" in text or text[0] == "/":
49-
suffix = "" if case_sensitive else "i"
50-
return "/" + re.sub(r"\s+", "\\\\s+", escape_for_regex(text)) + "/" + suffix
51-
return text
47+
return json.dumps(text) + ("s" if exact else "i")
5248

5349

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

0 commit comments

Comments
 (0)