Skip to content

[wdspec] test browser.createUserContext:proxy parameter #52691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 22, 2025
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
51 changes: 51 additions & 0 deletions webdriver/tests/bidi/browser/create_user_context/invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,54 @@
async def test_accept_insecure_certs_invalid_type(create_user_context, value):
with pytest.raises(error.InvalidArgumentException):
await create_user_context(accept_insecure_certs=value)


@pytest.mark.parametrize("value", [False, 42, "foo", []])
async def test_proxy_invalid_type(create_user_context, value):
with pytest.raises(error.InvalidArgumentException):
await create_user_context(
proxy=value)


@pytest.mark.parametrize("value", [{}])
async def test_proxy_invalid_value(create_user_context, value):
with pytest.raises(error.InvalidArgumentException):
await create_user_context(
proxy=value)


@pytest.mark.parametrize("value", [False, 42, {}, []])
async def test_proxy_proxy_type_invalid_type(create_user_context, value):
with pytest.raises(error.InvalidArgumentException):
await create_user_context(
proxy={
"proxyType": value
})


async def test_proxy_proxy_type_invalid_value(create_user_context):
with pytest.raises(error.InvalidArgumentException):
await create_user_context(
proxy={
"proxyType": "SOME_UNKNOWN_TYPE"
})


async def test_proxy_proxy_type_manual_socks_version_without_socks_proxy(
create_user_context):
with pytest.raises(error.InvalidArgumentException):
await create_user_context(
proxy={
"proxyType": "manual",
"socksVersion": 0
})


async def test_proxy_proxy_type_manual_socks_proxy_without_socks_version(
create_user_context):
with pytest.raises(error.InvalidArgumentException):
await create_user_context(
proxy={
"proxyType": "manual",
"socksProxy": "127.0.0.1:1080"
})
74 changes: 74 additions & 0 deletions webdriver/tests/bidi/browser/create_user_context/proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import pytest

from .. import get_user_context_ids

pytestmark = pytest.mark.asyncio


@pytest.fixture
def create_user_context_with_proxy(bidi_session, create_user_context):
async def create_user_context_with_proxy(proxy):
user_context = await create_user_context(proxy=proxy)

assert user_context in await get_user_context_ids(bidi_session)

return user_context

return create_user_context_with_proxy


async def test_system(create_user_context_with_proxy):
await create_user_context_with_proxy({
"proxyType": "system"
})
# TODO: check the proxy is actually set.


async def test_autodetect(
create_user_context_with_proxy):
await create_user_context_with_proxy({
"proxyType": "autodetect"
})
# TODO: check the proxy is actually set.


async def test_direct(create_user_context_with_proxy):
await create_user_context_with_proxy({
"proxyType": "direct"
})
# TODO: check the proxy is actually set.


@pytest.mark.parametrize("ftpProxy", [None, "127.0.0.1:21"])
@pytest.mark.parametrize("httpProxy", [None, "127.0.0.1:80"])
@pytest.mark.parametrize("sslProxy", [None, "127.0.0.1:443"])
@pytest.mark.parametrize("noProxy", [None, ["127.0.0.1"]])
@pytest.mark.parametrize("socks", [None, {
"socksProxy": "127.0.0.1:1080",
"socksVersion": 5}])
async def test_manual(create_user_context_with_proxy,
ftpProxy, httpProxy, sslProxy,
noProxy, socks):
proxy = {
"proxyType": "manual"
}

if ftpProxy is not None:
proxy["ftpProxy"] = ftpProxy

if httpProxy is not None:
proxy["httpProxy"] = httpProxy

if sslProxy is not None:
proxy["sslProxy"] = sslProxy

if noProxy is not None:
proxy["noProxy"] = noProxy

if socks is not None:
proxy.update(socks)

await create_user_context_with_proxy(proxy)
# TODO: check the proxy is actually set.

# TODO: test "proxyType": "pac"