Skip to content

Commit faa256d

Browse files
authored
chore(roll): roll Playwright to 1.37.0-alpha-aug-8-2023 (#2035)
1 parent 7ef13c3 commit faa256d

File tree

11 files changed

+148
-38
lines changed

11 files changed

+148
-38
lines changed

README.md

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

55
| | Linux | macOS | Windows |
66
| :--- | :---: | :---: | :---: |
7-
| Chromium <!-- GEN:chromium-version -->115.0.5790.75<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->116.0.5845.62<!-- GEN:stop --> ||||
88
| WebKit <!-- GEN:webkit-version -->17.0<!-- GEN:stop --> ||||
99
| Firefox <!-- GEN:firefox-version -->115.0<!-- GEN:stop --> ||||
1010

playwright/_impl/_artifact.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@ async def failure(self) -> Optional[str]:
4747
async def delete(self) -> None:
4848
await self._channel.send("delete")
4949

50+
async def read_info_buffer(self) -> bytes:
51+
stream = cast(Stream, from_channel(await self._channel.send("stream")))
52+
buffer = await stream.read_all()
53+
return buffer
54+
5055
async def cancel(self) -> None:
5156
await self._channel.send("cancel")

playwright/_impl/_browser.py

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

15-
import base64
1615
import json
1716
from pathlib import Path
1817
from types import SimpleNamespace
19-
from typing import TYPE_CHECKING, Dict, List, Pattern, Union, cast
18+
from typing import TYPE_CHECKING, Dict, List, Optional, Pattern, Union, cast
2019

2120
from playwright._impl._api_structures import (
2221
Geolocation,
@@ -25,6 +24,7 @@
2524
StorageState,
2625
ViewportSize,
2726
)
27+
from playwright._impl._artifact import Artifact
2828
from playwright._impl._browser_context import BrowserContext
2929
from playwright._impl._cdp_session import CDPSession
3030
from playwright._impl._connection import ChannelOwner, from_channel
@@ -39,6 +39,7 @@
3939
async_readfile,
4040
is_safe_close_error,
4141
locals_to_params,
42+
make_dirs_for_file,
4243
prepare_record_har_options,
4344
)
4445
from playwright._impl._network import serialize_headers
@@ -61,6 +62,7 @@ def __init__(
6162
self._is_connected = True
6263
self._is_closed_or_closing = False
6364
self._should_close_connection_on_close = False
65+
self._cr_tracing_path: Optional[str] = None
6466

6567
self._contexts: List[BrowserContext] = []
6668
self._channel.on("close", lambda _: self._on_close())
@@ -207,12 +209,20 @@ async def start_tracing(
207209
if page:
208210
params["page"] = page._channel
209211
if path:
212+
self._cr_tracing_path = str(path)
210213
params["path"] = str(path)
211214
await self._channel.send("startTracing", params)
212215

213216
async def stop_tracing(self) -> bytes:
214-
encoded_binary = await self._channel.send("stopTracing")
215-
return base64.b64decode(encoded_binary)
217+
artifact = cast(Artifact, from_channel(await self._channel.send("stopTracing")))
218+
buffer = await artifact.read_info_buffer()
219+
await artifact.delete()
220+
if self._cr_tracing_path:
221+
make_dirs_for_file(self._cr_tracing_path)
222+
with open(self._cr_tracing_path, "wb") as f:
223+
f.write(buffer)
224+
self._cr_tracing_path = None
225+
return buffer
216226

217227

218228
async def prepare_browser_context_params(params: Dict) -> None:

playwright/_impl/_browser_type.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from playwright._impl._connection import (
3030
ChannelOwner,
3131
Connection,
32+
filter_none,
3233
from_channel,
3334
from_nullable_channel,
3435
)
@@ -187,6 +188,7 @@ async def connect(
187188
timeout: float = None,
188189
slow_mo: float = None,
189190
headers: Dict[str, str] = None,
191+
expose_network: str = None,
190192
) -> Browser:
191193
if timeout is None:
192194
timeout = 30000
@@ -198,12 +200,15 @@ async def connect(
198200
pipe_channel = (
199201
await local_utils._channel.send_return_as_dict(
200202
"connect",
201-
{
202-
"wsEndpoint": ws_endpoint,
203-
"headers": headers,
204-
"slowMo": slow_mo,
205-
"timeout": timeout,
206-
},
203+
filter_none(
204+
{
205+
"wsEndpoint": ws_endpoint,
206+
"headers": headers,
207+
"slowMo": slow_mo,
208+
"timeout": timeout,
209+
"exposeNetwork": expose_network,
210+
}
211+
),
207212
)
208213
)["pipe"]
209214
transport = JsonPipeTransport(self._connection._loop, pipe_channel)

playwright/_impl/_locator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def locator(
241241
raise Error("Locators must belong to the same frame.")
242242
return Locator(
243243
self._frame,
244-
f"{self._selector} >> {selector_or_locator._selector}",
244+
f"{self._selector} >> internal:chain={json.dumps(selector_or_locator._selector)}",
245245
has_text=has_text,
246246
has_not_text=has_not_text,
247247
has_not=has_not,

playwright/_impl/_stream.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ async def save_as(self, path: Union[str, Path]) -> None:
3535
None, lambda: file.write(base64.b64decode(binary))
3636
)
3737
await self._loop.run_in_executor(None, lambda: file.close())
38+
39+
async def read_all(self) -> bytes:
40+
binary = b""
41+
while True:
42+
chunk = await self._channel.send("read", {"size": 1024 * 1024})
43+
if not chunk:
44+
break
45+
binary += base64.b64decode(chunk)
46+
return binary

playwright/async_api/_generated.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4277,6 +4277,9 @@ async def set_content(
42774277
) -> None:
42784278
"""Frame.set_content
42794279

4280+
This method internally calls [document.write()](https://developer.mozilla.org/en-US/docs/Web/API/Document/write),
4281+
inheriting all its specific characteristics and behaviors.
4282+
42804283
Parameters
42814284
----------
42824285
html : str
@@ -9156,6 +9159,9 @@ async def set_content(
91569159
) -> None:
91579160
"""Page.set_content
91589161

9162+
This method internally calls [document.write()](https://developer.mozilla.org/en-US/docs/Web/API/Document/write),
9163+
inheriting all its specific characteristics and behaviors.
9164+
91599165
Parameters
91609166
----------
91619167
html : str
@@ -9854,7 +9860,7 @@ async def route_from_har(
98549860
"""Page.route_from_har
98559861

98569862
If specified the network requests that are made in the page will be served from the HAR file. Read more about
9857-
[Replaying from HAR](https://playwright.dev/python/docs/network#replaying-from-har).
9863+
[Replaying from HAR](https://playwright.dev/python/docs/mock#replaying-from-har).
98589864

98599865
Playwright will not serve requests intercepted by Service Worker from the HAR file. See
98609866
[this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when
@@ -13592,7 +13598,7 @@ async def route_from_har(
1359213598
"""BrowserContext.route_from_har
1359313599

1359413600
If specified the network requests that are made in the context will be served from the HAR file. Read more about
13595-
[Replaying from HAR](https://playwright.dev/python/docs/network#replaying-from-har).
13601+
[Replaying from HAR](https://playwright.dev/python/docs/mock#replaying-from-har).
1359613602

1359713603
Playwright will not serve requests intercepted by Service Worker from the HAR file. See
1359813604
[this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when
@@ -14088,7 +14094,7 @@ async def new_context(
1408814094
is_mobile : Union[bool, None]
1408914095
Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device,
1409014096
so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more
14091-
about [mobile emulation](../emulation.md#isMobile).
14097+
about [mobile emulation](../emulation.md#ismobile).
1409214098
has_touch : Union[bool, None]
1409314099
Specifies if viewport supports touch events. Defaults to false. Learn more about
1409414100
[mobile emulation](../emulation.md#devices).
@@ -14302,7 +14308,7 @@ async def new_page(
1430214308
is_mobile : Union[bool, None]
1430314309
Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device,
1430414310
so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more
14305-
about [mobile emulation](../emulation.md#isMobile).
14311+
about [mobile emulation](../emulation.md#ismobile).
1430614312
has_touch : Union[bool, None]
1430714313
Specifies if viewport supports touch events. Defaults to false. Learn more about
1430814314
[mobile emulation](../emulation.md#devices).
@@ -14847,7 +14853,7 @@ async def launch_persistent_context(
1484714853
is_mobile : Union[bool, None]
1484814854
Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device,
1484914855
so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more
14850-
about [mobile emulation](../emulation.md#isMobile).
14856+
about [mobile emulation](../emulation.md#ismobile).
1485114857
has_touch : Union[bool, None]
1485214858
Specifies if viewport supports touch events. Defaults to false. Learn more about
1485314859
[mobile emulation](../emulation.md#devices).
@@ -15033,7 +15039,8 @@ async def connect(
1503315039
*,
1503415040
timeout: typing.Optional[float] = None,
1503515041
slow_mo: typing.Optional[float] = None,
15036-
headers: typing.Optional[typing.Dict[str, str]] = None
15042+
headers: typing.Optional[typing.Dict[str, str]] = None,
15043+
expose_network: typing.Optional[str] = None
1503715044
) -> "Browser":
1503815045
"""BrowserType.connect
1503915046

@@ -15052,6 +15059,20 @@ async def connect(
1505215059
on. Defaults to 0.
1505315060
headers : Union[Dict[str, str], None]
1505415061
Additional HTTP headers to be sent with web socket connect request. Optional.
15062+
expose_network : Union[str, None]
15063+
This option exposes network available on the connecting client to the browser being connected to. Consists of a
15064+
list of rules separated by comma.
15065+
15066+
Available rules:
15067+
1. Hostname pattern, for example: `example.com`, `*.org:99`, `x.*.y.com`, `*foo.org`.
15068+
1. IP literal, for example: `127.0.0.1`, `0.0.0.0:99`, `[::1]`, `[0:0::1]:99`.
15069+
1. `<loopback>` that matches local loopback interfaces: `localhost`, `*.localhost`, `127.0.0.1`, `[::1]`.
15070+
15071+
Some common examples:
15072+
1. `"*"` to expose all network.
15073+
1. `"<loopback>"` to expose localhost network.
15074+
1. `"*.test.internal-domain,*.staging.internal-domain,<loopback>"` to expose test/staging deployments and
15075+
localhost.
1505515076

1505615077
Returns
1505715078
-------
@@ -15064,6 +15085,7 @@ async def connect(
1506415085
timeout=timeout,
1506515086
slow_mo=slow_mo,
1506615087
headers=mapping.to_impl(headers),
15088+
expose_network=expose_network,
1506715089
)
1506815090
)
1506915091

@@ -16833,7 +16855,8 @@ async def blur(self, *, timeout: typing.Optional[float] = None) -> None:
1683316855
async def all(self) -> typing.List["Locator"]:
1683416856
"""Locator.all
1683516857

16836-
When locator points to a list of elements, returns array of locators, pointing to respective elements.
16858+
When the locator points to a list of elements, this returns an array of locators, pointing to their respective
16859+
elements.
1683716860

1683816861
**NOTE** `locator.all()` does not wait for elements to match the locator, and instead immediately returns
1683916862
whatever is present in the page. When the list of elements changes dynamically, `locator.all()` will
@@ -17803,6 +17826,9 @@ async def type(
1780317826
) -> None:
1780417827
"""Locator.type
1780517828

17829+
**NOTE** In most cases, you should use `locator.fill()` instead. You only need to type characters if there
17830+
is special keyboard handling on the page.
17831+
1780617832
Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the
1780717833
text.
1780817834

@@ -19908,16 +19934,16 @@ async def to_have_text(
1990819934
from playwright.sync_api import expect
1990919935

1991019936
# ✓ Has the right items in the right order
19911-
await expect(page.locator(\"ul > li\")).to_have_text([\"Text 1\", \"Text 2\", \"Text 3\"])
19937+
expect(page.locator(\"ul > li\")).to_have_text([\"Text 1\", \"Text 2\", \"Text 3\"])
1991219938

1991319939
# ✖ Wrong order
19914-
await expect(page.locator(\"ul > li\")).to_have_text([\"Text 3\", \"Text 2\", \"Text 1\"])
19940+
expect(page.locator(\"ul > li\")).to_have_text([\"Text 3\", \"Text 2\", \"Text 1\"])
1991519941

1991619942
# ✖ Last item does not match
19917-
await expect(page.locator(\"ul > li\")).to_have_text([\"Text 1\", \"Text 2\", \"Text\"])
19943+
expect(page.locator(\"ul > li\")).to_have_text([\"Text 1\", \"Text 2\", \"Text\"])
1991819944

1991919945
# ✖ Locator points to the outer list element, not to the list items
19920-
await expect(page.locator(\"ul\")).to_have_text([\"Text 1\", \"Text 2\", \"Text 3\"])
19946+
expect(page.locator(\"ul\")).to_have_text([\"Text 1\", \"Text 2\", \"Text 3\"])
1992119947
```
1992219948

1992319949
Parameters

0 commit comments

Comments
 (0)