Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DRIVER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b4d016aadc5cbd2b898a284307975fe73e05483d
8124fc39233c4c349b9dbebd4abc4103738eae81
1 change: 1 addition & 0 deletions playwright/_impl/_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,7 @@
"isLocal": "boolean?",
"noDefaults": "boolean?",
"isWebView": "boolean?",
"maxPageAttachTime": "float?",
"artifactsDir": "string?",
"transport": "binary?",
},
Expand Down
39 changes: 24 additions & 15 deletions playwright/_impl/browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,7 @@ async def launch(

# Not ported: the logger option (JavaScript only).
options = {**(self._playwright._default_launch_options or {}), **options}
launch_options = {
**_launch_params(options),
"ignoreDefaultArgs": (
options["ignore_default_args"]
if _is_array(options.get("ignore_default_args"))
else None
),
"ignoreAllDefaultArgs": bool(options.get("ignore_default_args"))
and not _is_array(options.get("ignore_default_args")),
"env": (
env_object_to_array(options["env"])
if options.get("env") is not None
else None
),
}
launch_options = to_launch_params(options)
browser = Browser.from_(
(
await self._channel.launch(
Expand Down Expand Up @@ -373,6 +359,7 @@ async def connect(
return await self._connect({**options, "endpoint": endpoint})

async def _connect(self, params: Dict[str, Any]) -> Browser:
# Not ported: launchOptions (langs: js).
browser = await connect_to_browser(
self._playwright, {"browser_name": self.name, **params}
)
Expand All @@ -388,6 +375,8 @@ async def connect_over_cdp(
is_local: Optional[bool],
no_defaults: Optional[bool],
artifacts_dir: Optional[Union[str, Path]],
# Python: an undocumented option, available only to implementation callers.
max_page_attach_time: Optional[float] = None,
) -> Browser:
# Not ported: connectOverCDP() with an options object or with a
# ConnectOverCDPTransport (JavaScript only), so there is no transport.
Expand All @@ -399,6 +388,7 @@ async def connect_over_cdp(
headers=headers,
is_local=is_local,
no_defaults=no_defaults,
max_page_attach_time=max_page_attach_time,
artifacts_dir=_to_path_string(artifacts_dir),
)
if endpoint_url and self.name != "chromium" and self.name != "webkit":
Expand All @@ -417,6 +407,7 @@ async def connect_over_cdp(
noDefaults=params.get("no_defaults"),
# Python: the Python API has no isWebView option.
isWebView=None,
maxPageAttachTime=params.get("max_page_attach_time"),
artifactsDir=params.get("artifacts_dir"),
timeout=TimeoutSettings().timeout(params.get("timeout")),
)
Expand All @@ -439,6 +430,24 @@ def __repr__(self) -> str:
return f"<BrowserType name={self.name} executable_path={self.executable_path}>"


def to_launch_params(options: Dict[str, Any]) -> Dict[str, Any]:
return {
**_launch_params(options),
"ignoreDefaultArgs": (
options["ignore_default_args"]
if _is_array(options.get("ignore_default_args"))
else None
),
"ignoreAllDefaultArgs": bool(options.get("ignore_default_args"))
and not _is_array(options.get("ignore_default_args")),
"env": (
env_object_to_array(options["env"])
if options.get("env") is not None
else None
),
}


# Not ported: isConnectionTransport(), for connectOverCDP() with a
# ConnectOverCDPTransport (JavaScript only).

Expand Down
1 change: 1 addition & 0 deletions playwright/_impl/protocol/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@
"isLocal": t_optional(t_boolean),
"noDefaults": t_optional(t_boolean),
"isWebView": t_optional(t_boolean),
"maxPageAttachTime": t_optional(t_float),
"artifactsDir": t_optional(t_string),
"transport": t_optional(t_binary),
}
Expand Down
2 changes: 2 additions & 0 deletions playwright/_impl/protocol_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,7 @@ def connectOverCDP(
isLocal: Optional[bool],
noDefaults: Optional[bool],
isWebView: Optional[bool],
maxPageAttachTime: Optional[float],
artifactsDir: Optional[str],
transport: Optional[str],
timeout: float = 0,
Expand All @@ -1896,6 +1897,7 @@ def connectOverCDP(
"isLocal": isLocal,
"noDefaults": noDefaults,
"isWebView": isWebView,
"maxPageAttachTime": maxPageAttachTime,
"artifactsDir": artifactsDir,
"transport": transport,
},
Expand Down
63 changes: 61 additions & 2 deletions tests/async/library/chromium/test_connect_over_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import pytest

from playwright._impl._async_base import mapping as api_mapping
from playwright._impl.utils.tasks import fire_and_forget
from playwright.async_api import (
Browser,
BrowserType,
Expand Down Expand Up @@ -673,7 +675,7 @@ def handle(request: TestServerRequest) -> None:
endpoint_url=server.PREFIX,
)
assert (
f"BrowserType.connect_over_cdp: Unexpected status 404 when connecting to {server.PREFIX}/json/version/"
f"Unexpected status 404 when connecting to {server.PREFIX}/json/version/"
in exc_info.value.message
)

Expand All @@ -691,7 +693,7 @@ def handle(request: TestServerRequest) -> None:
await browser_type.connect_over_cdp(
endpoint_url=server.PREFIX,
)
assert "BrowserType.connect_over_cdp: Invalid URL" in exc_info.value.message
assert "Invalid URL" in exc_info.value.message


async def test_CD_022_should_connect_to_an_existing_cdp_session_when_passed_as_a_first_argument(
Expand Down Expand Up @@ -961,6 +963,63 @@ async def test_CD_035_no_defaults_should_not_affect_new_contexts(
await browser_server.close()


async def test_CD_054_should_not_wait_for_a_busy_page_longer_than_max_page_attach_time(
browser_type: BrowserType, server: Server, launch_arguments: Dict, port: int
) -> None:
# The busy page should not share a renderer with the other page.
browser_server = await launch(
browser_type, launch_arguments, port, "--site-per-process"
)
try:
cdp_browser1 = await browser_type.connect_over_cdp(
endpoint_url=f"http://127.0.0.1:{port}/",
)
context1 = cdp_browser1.contexts[0]
page1 = await context1.new_page()
await page1.goto(server.CROSS_PROCESS_PREFIX + "/title.html")
busy_page1 = await context1.new_page()
await busy_page1.goto(server.EMPTY_PAGE)
async with busy_page1.expect_event(
"console", predicate=lambda message: message.text == "busy"
):
fire_and_forget(
busy_page1.evaluate(
"""() => {
console.log('busy');
const start = Date.now();
while (Date.now() - start < 5000) {}
}"""
)
)
# Python: the option is undocumented; call the implementation directly.
cdp_browser2: Browser = api_mapping.from_impl(
await browser_type._impl_obj.connect_over_cdp(
endpoint_url=f"http://127.0.0.1:{port}/",
timeout=None,
slow_mo=None,
headers=None,
is_local=None,
no_defaults=None,
artifacts_dir=None,
max_page_attach_time=500,
)
)
context2 = cdp_browser2.contexts[0]
pages = context2.pages
assert [page.url for page in pages] == [
server.CROSS_PROCESS_PREFIX + "/title.html"
]
assert await pages[0].title() == "Woof-Woof"
# The busy page is reported when its renderer responds again.
busy_page2 = await context2.wait_for_event("page")
assert busy_page2.url == server.EMPTY_PAGE
assert await busy_page2.evaluate("() => 1 + 1") == 2
await cdp_browser2.close()
await cdp_browser1.close()
finally:
await browser_server.close()


async def test_CD_053_should_connect_when_another_client_inspects_a_terminated_shared_worker(
browser_type: BrowserType, server: Server, launch_arguments: Dict, port: int
) -> None:
Expand Down
12 changes: 6 additions & 6 deletions tests/async/library/test_browsercontext_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def test_FE_092_should_throw_on_network_error(
server.set_route("/test", destroy_socket)
with pytest.raises(Error) as exc_info:
await context.request.get(server.PREFIX + "/test")
assert "APIRequestContext.get: socket hang up" in exc_info.value.message
assert "socket hang up" in exc_info.value.message


async def test_FE_093_should_throw_on_network_error_after_redirect(
Expand All @@ -221,7 +221,7 @@ async def test_FE_093_should_throw_on_network_error_after_redirect(
server.set_route("/test", destroy_socket)
with pytest.raises(Error) as exc_info:
await context.request.get(server.PREFIX + "/redirect")
assert "APIRequestContext.get: socket hang up" in exc_info.value.message
assert "socket hang up" in exc_info.value.message


async def test_FE_094_should_throw_on_network_error_when_sending_body(
Expand All @@ -230,7 +230,7 @@ async def test_FE_094_should_throw_on_network_error_when_sending_body(
server.set_route("/test", send_partial_body_and_destroy_socket)
with pytest.raises(Error) as exc_info:
await context.request.get(server.PREFIX + "/test")
assert "APIRequestContext.get: aborted" in exc_info.value.message
assert "aborted" in exc_info.value.message


async def test_FE_095_should_throw_on_network_error_when_sending_body_after_redirect(
Expand All @@ -240,7 +240,7 @@ async def test_FE_095_should_throw_on_network_error_when_sending_body_after_redi
server.set_route("/test", send_partial_body_and_destroy_socket)
with pytest.raises(Error) as exc_info:
await context.request.get(server.PREFIX + "/redirect")
assert "APIRequestContext.get: aborted" in exc_info.value.message
assert "aborted" in exc_info.value.message


async def test_FE_096_should_add_session_cookies_to_request(
Expand Down Expand Up @@ -1172,7 +1172,7 @@ async def test_FE_148_should_support_timeout_option(

with pytest.raises(Error) as exc_info:
await context.request.get(server.PREFIX + "/slow", timeout=10)
assert "APIRequestContext.get: Timeout 10ms exceeded" in exc_info.value.message
assert "Timeout 10ms exceeded" in exc_info.value.message


async def test_FE_149_should_support_a_timeout_of_0(
Expand All @@ -1198,7 +1198,7 @@ async def test_FE_150_should_respect_timeout_after_redirects(
context.set_default_timeout(100)
with pytest.raises(Error) as exc_info:
await context.request.get(server.PREFIX + "/redirect")
assert "APIRequestContext.get: Timeout 100ms exceeded" in exc_info.value.message
assert "Timeout 100ms exceeded" in exc_info.value.message


async def test_FE_151_should_not_hang_on_a_brotli_encoded_range_request(
Expand Down
2 changes: 1 addition & 1 deletion tests/async/library/test_browsercontext_storage_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def test_ST_003_should_report_good_error_if_the_url_is_not_valid(
],
}
)
assert "Browser.new_context: Error setting storage state:" in exc_info.value.message
assert "Error setting storage state:" in exc_info.value.message
assert "foo" in exc_info.value.message


Expand Down
43 changes: 5 additions & 38 deletions tests/async/library/test_browsertype_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
List,
Optional,
)
from urllib.parse import urlparse

import pytest

Expand Down Expand Up @@ -77,6 +76,7 @@ async def connect_browser(
) -> Browser:
"""Port of the connect fixture: passes the launch options for run-server along."""
with redirect_port_forwarding_for_test(browser_type, redirect_port_for_test):
# Python: launchOptions is JavaScript-only; send its header directly.
return await browser_type.connect(
ws_endpoint,
headers={
Expand Down Expand Up @@ -305,7 +305,7 @@ def handle_ws(ws: WebSocketProtocol) -> None:
server.once_web_socket_connection(handle_ws)
with pytest.raises(Error) as exc_info:
await connect(f"ws://localhost:{server.PORT}/ws")
assert "BrowserType.connect: Oh my!" in exc_info.value.message
assert "Oh my!" in exc_info.value.message


@pytest.mark.parametrize("kind", KINDS)
Expand Down Expand Up @@ -471,7 +471,7 @@ def upgrade() -> None:
server.set_route("/ws-slow", handle_ws_slow)
with pytest.raises(Error) as exc_info:
await connect(f"ws://localhost:{server.PORT}/ws-slow", timeout=1000)
assert "BrowserType.connect: Timeout 1000ms exceeded" in exc_info.value.message
assert "Timeout 1000ms exceeded" in exc_info.value.message


@pytest.mark.parametrize("kind", KINDS)
Expand All @@ -484,7 +484,7 @@ async def test_BT_045_should_timeout_in_connect_while_connecting(
server.once_web_socket_connection(server_web_sockets.append)
with pytest.raises(Error) as exc_info:
await connect(f"ws://localhost:{server.PORT}/ws", timeout=100)
assert "BrowserType.connect: Timeout 100ms exceeded" in exc_info.value.message
assert "Timeout 100ms exceeded" in exc_info.value.message


@pytest.mark.parametrize("kind", KINDS)
Expand Down Expand Up @@ -1138,6 +1138,7 @@ async def test_BT_071_should_be_able_to_connect_when_the_ws_endpoint_is_passed_a
start_remote_server: RemoteServerStarter,
) -> None:
remote_server = start_remote_server(kind)
# Python: launchOptions is JavaScript-only; send its header directly.
browser = await browser_type.connect(
endpoint=remote_server.ws_endpoint,
headers={
Expand Down Expand Up @@ -1376,20 +1377,6 @@ async def test_BT_078_set_input_files_should_preserve_last_modified_timestamp(
), f"expected: {expected_timestamps}; actual: {timestamps}"


@pytest.mark.parametrize("kind", KINDS)
async def test_BT_079_should_connect_over_http(
kind: str,
connect: Callable[..., Awaitable[Browser]],
start_remote_server: RemoteServerStarter,
) -> None:
remote_server = start_remote_server(kind)

url = urlparse(remote_server.ws_endpoint)
browser = await connect(f"http://localhost:{url.port}")
assert browser.version
await browser.close()


def skip_socks_proxy(kind: str) -> None:
"""Port of the test.skip() of the 'socks proxy' describe."""
if kind == KIND_LAUNCH_SERVER:
Expand Down Expand Up @@ -1872,23 +1859,3 @@ async def test_BT_094_should_filter_local_paths_from_unsafe_launch_options(

actions = trace_actions(read_trace(trace_path))
assert "Frame.setContent" in actions


async def test_BT_095_should_timeout_after_redirect_when_connecting_over_http(
playwright: Playwright,
connect: Callable[..., Awaitable[Browser]],
server: Server,
) -> None:
server.set_redirect("/connect/json", "/connect/slow")
aborted: List[bool] = []

def handle_slow(request: TestServerRequest) -> None:
request.notifyFinish().addErrback(lambda _: aborted.append(True))

server.set_route("/connect/slow", handle_slow)
with pytest.raises(Error) as exc_info:
await connect(
f"{server.PREFIX}/connect", timeout=2000, headers={"Connection": "Close"}
)
assert "Timeout 2000ms exceeded." in exc_info.value.message
await poll(playwright, lambda: aborted == [True])
2 changes: 1 addition & 1 deletion tests/async/library/test_browsertype_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def test_BT_010_should_reject_if_launched_browser_fails_immediately(
assert "Failed to launch" in exc_info.value.message
else:
assert re.search(
r"browserType\.launch(.|\n)*(spawn UNKNOWN|spawn EFTYPE|Browser logs:)",
r"(spawn UNKNOWN|spawn EFTYPE|Browser logs:)",
exc_info.value.message,
re.IGNORECASE | re.MULTILINE,
)
Expand Down
Loading
Loading