Skip to content

Commit bc88ac9

Browse files
fix: patch bug in locals_to_params (#2300)
1 parent 04b7851 commit bc88ac9

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ coverage.xml
1818
junit/
1919
htmldocs/
2020
utils/docker/dist/
21+
Pipfile
22+
Pipfile.lock
23+
.venv/

playwright/_impl/_helper.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,11 @@ def locals_to_params(args: Dict) -> Dict:
246246
if key == "self":
247247
continue
248248
if args[key] is not None:
249-
copy[key] = args[key]
249+
copy[key] = (
250+
args[key]
251+
if not isinstance(args[key], Dict)
252+
else locals_to_params(args[key])
253+
)
250254
return copy
251255

252256

tests/async/test_browsercontext_proxy.py

+23
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,29 @@ async def test_should_use_proxy(
4848
assert await page.title() == "Served by the proxy"
4949

5050

51+
async def test_proxy_should_allow_none_for_optional_settings(
52+
context_factory: "Callable[..., asyncio.Future[BrowserContext]]", server: Server
53+
) -> None:
54+
server.set_route(
55+
"/target.html",
56+
lambda r: (
57+
r.write(b"<html><title>Served by the proxy</title></html>"),
58+
r.finish(),
59+
),
60+
)
61+
context = await context_factory(
62+
proxy={
63+
"server": f"localhost:{server.PORT}",
64+
"username": None,
65+
"password": None,
66+
"bypass": None,
67+
}
68+
)
69+
page = await context.new_page()
70+
await page.goto("http://non-existent.com/target.html")
71+
assert await page.title() == "Served by the proxy"
72+
73+
5174
async def test_should_use_proxy_for_second_page(
5275
context_factory: "Callable[..., Awaitable[BrowserContext]]", server: Server
5376
) -> None:

tests/async/test_proxy.py

+23
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ async def test_should_use_proxy(
4646
assert await page.title() == "Served by the proxy"
4747

4848

49+
async def test_proxy_should_allow_none_for_optional_settings(
50+
browser_factory: "Callable[..., asyncio.Future[Browser]]", server: Server
51+
) -> None:
52+
server.set_route(
53+
"/target.html",
54+
lambda r: (
55+
r.write(b"<html><title>Served by the proxy</title></html>"),
56+
r.finish(),
57+
),
58+
)
59+
browser = await browser_factory(
60+
proxy={
61+
"server": f"localhost:{server.PORT}",
62+
"username": None,
63+
"password": None,
64+
"bypass": None,
65+
}
66+
)
67+
page = await browser.new_page()
68+
await page.goto("http://non-existent.com/target.html")
69+
assert await page.title() == "Served by the proxy"
70+
71+
4972
async def test_should_use_proxy_for_second_page(
5073
browser_factory: "Callable[..., asyncio.Future[Browser]]", server: Server
5174
) -> None:

0 commit comments

Comments
 (0)