From 6a660c3b6610cd81026133a22f9699b6e33fd5cd Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Fri, 13 Nov 2026 01:07:51 +0000 Subject: [PATCH] fix: honor slowmo when connecting to remote browsers --- .../pytest_playwright.py | 6 +++++- .../pytest_playwright/pytest_playwright.py | 6 +++++- tests/test_sync.py | 17 ++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py b/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py index ba9ccd8..63a16e3 100644 --- a/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py +++ b/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py @@ -516,12 +516,16 @@ def launch_browser( async def launch(**kwargs: Dict) -> Browser: launch_options = {**browser_type_launch_args, **kwargs} if connect_options: + remote_launch_options = dict(launch_options) + # remote launch headers bypass the Python API's option-name conversion + if "slow_mo" in remote_launch_options: + remote_launch_options["slowMo"] = remote_launch_options.pop("slow_mo") browser = await browser_type.connect( **( { **connect_options, "headers": { - "x-playwright-launch-options": json.dumps(launch_options), + "x-playwright-launch-options": json.dumps(remote_launch_options), **(connect_options.get("headers") or {}), }, } diff --git a/pytest-playwright/pytest_playwright/pytest_playwright.py b/pytest-playwright/pytest_playwright/pytest_playwright.py index aeb22fa..5dde3d7 100644 --- a/pytest-playwright/pytest_playwright/pytest_playwright.py +++ b/pytest-playwright/pytest_playwright/pytest_playwright.py @@ -513,12 +513,16 @@ def launch_browser( def launch(**kwargs: Dict) -> Browser: launch_options = {**browser_type_launch_args, **kwargs} if connect_options: + remote_launch_options = dict(launch_options) + # remote launch headers bypass the Python API's option-name conversion + if "slow_mo" in remote_launch_options: + remote_launch_options["slowMo"] = remote_launch_options.pop("slow_mo") browser = browser_type.connect( **( { **connect_options, "headers": { - "x-playwright-launch-options": json.dumps(launch_options), + "x-playwright-launch-options": json.dumps(remote_launch_options), **(connect_options.get("headers") or {}), }, } diff --git a/tests/test_sync.py b/tests/test_sync.py index 10f73e4..a7d263c 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -1603,7 +1603,8 @@ def test_with_page(page): ] -def test_connect_options_should_work(testdir: pytest.Testdir) -> None: +@pytest.mark.parametrize("slowmo", [0, 500]) +def test_connect_options_should_work(testdir: pytest.Testdir, slowmo: int) -> None: server_process = None try: testdir.makeconftest( @@ -1619,11 +1620,17 @@ def connect_options(): ) testdir.makepyfile( """ - def test_connect_options(page): - assert page.evaluate("1 + 1") == 2 + import time + + def test_connect_options(page, pytestconfig): + page.set_content("") + started = time.monotonic() + for _ in range(5): + page.get_by_role("button").click() + assert time.monotonic() - started >= 5 * pytestconfig.getoption("--slowmo") / 1000 """ ) - result = testdir.runpytest() + result = testdir.runpytest("--slowmo", str(slowmo)) assert "connect ECONNREFUSED" in "\n".join(result.outlines + result.errlines) server_process = subprocess.Popen( ["playwright", "run-server", "--port=1234"], @@ -1634,7 +1641,7 @@ def test_connect_options(page): assert stdout if "Listening on" in str(stdout.readline()): break - result = testdir.runpytest() + result = testdir.runpytest("--slowmo", str(slowmo)) result.assert_outcomes(passed=1) finally: assert server_process