Skip to content

test: e2e test on *.test domains #3448

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

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions tests/bluetooth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ async def request_device(websocket,

async def setup_granted_device(websocket,
context_id: str,
html,
url,
optional_services: list[str] = []) -> str:
"""Navigates, sets up simulation, and grants device access to the page.

Combines navigation, device simulation setup, and device request steps.
The page will have access to the bluetooth device via the `device`
JavaScript variable after this function completes.
"""
await goto_url(websocket, context_id, html())
await goto_url(websocket, context_id, url)
device_address = await setup_device(websocket, context_id)
await subscribe(websocket, ['bluetooth.requestDevicePromptUpdated'])
await request_device(websocket, context_id, optional_services)
Expand Down
30 changes: 19 additions & 11 deletions tests/bluetooth/test_characteristic_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@

CHARACTERISTIC_EVENT_GENERATED = 'bluetooth.characteristicEventGenerated'

# Bluetooth require secure context (either `Secure` or `SecureLocalhost`).
pytestmark = pytest.mark.parametrize('capabilities', [{
'acceptInsecureCerts': True
}],
indirect=True)

async def setup_characteristic(websocket, context_id: str, html,

async def setup_characteristic(websocket, context_id: str, url,
service_uuid: str, characteristic_uuid: str,
characteristic_properties):
device_address = await setup_granted_device(websocket, context_id, html,
device_address = await setup_granted_device(websocket, context_id, url,
[service_uuid])
await create_gatt_connection(websocket, context_id)
await simulate_service(websocket, context_id, device_address, service_uuid,
Expand Down Expand Up @@ -141,9 +147,10 @@ async def teardown(websocket, context_id):
'broadcast', 'read', 'writeWithoutResponse', 'write', 'notify', 'indicate',
'authenticatedSignedWrites'
])
async def test_bluetooth_simulateCharacteristic(websocket, context_id, html,
property):
device_address = await setup_granted_device(websocket, context_id, html,
async def test_bluetooth_simulateCharacteristic(websocket, context_id,
url_bad_ssl, property):
device_address = await setup_granted_device(websocket, context_id,
url_bad_ssl,
[HEART_RATE_SERVICE_UUID])
await create_gatt_connection(websocket, context_id)
await simulate_service(websocket, context_id, device_address,
Expand Down Expand Up @@ -304,8 +311,8 @@ async def test_bluetooth_remove_characteristic_uuid_with_properties(
'write_type', [('writeValueWithoutResponse', 'write-without-response'),
('writeValueWithResponse', 'write-with-response')])
async def test_bluetooth_characteristic_write_event(websocket, context_id,
html, write_type):
await setup_characteristic(websocket, context_id, html,
url_bad_ssl, write_type):
await setup_characteristic(websocket, context_id, url_bad_ssl,
HEART_RATE_SERVICE_UUID,
DATE_TIME_CHARACTERISTIC_UUID, {'write': True})
await subscribe(websocket, [CHARACTERISTIC_EVENT_GENERATED])
Expand Down Expand Up @@ -355,8 +362,8 @@ async def test_bluetooth_characteristic_write_event(websocket, context_id,

@pytest.mark.asyncio
async def test_bluetooth_characteristic_read_event(websocket, context_id,
html):
await setup_characteristic(websocket, context_id, html,
url_bad_ssl):
await setup_characteristic(websocket, context_id, url_bad_ssl,
HEART_RATE_SERVICE_UUID,
DATE_TIME_CHARACTERISTIC_UUID, {'read': True})
await subscribe(websocket, [CHARACTERISTIC_EVENT_GENERATED])
Expand Down Expand Up @@ -419,8 +426,9 @@ async def test_bluetooth_characteristic_read_event(websocket, context_id,

@pytest.mark.asyncio
async def test_bluetooth_characteristic_notification_event(
websocket, context_id, html):
device_address = await setup_characteristic(websocket, context_id, html,
websocket, context_id, url_bad_ssl):
device_address = await setup_characteristic(websocket, context_id,
url_bad_ssl,
HEART_RATE_SERVICE_UUID,
DATE_TIME_CHARACTERISTIC_UUID,
{'notify': True})
Expand Down
24 changes: 16 additions & 8 deletions tests/bluetooth/test_descriptor_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@

DESCRIPTOR_EVENT_GENERATED = 'bluetooth.descriptorEventGenerated'

# Bluetooth require secure context (either `Secure` or `SecureLocalhost`).
pytestmark = pytest.mark.parametrize('capabilities', [{
'acceptInsecureCerts': True
}],
indirect=True)

async def setup_descriptor(websocket, context_id: str, html, service_uuid: str,

async def setup_descriptor(websocket, context_id: str, url, service_uuid: str,
characteristic_uuid: str, characteristic_properties,
descriptor_uuid: str):
device_address = await setup_granted_device(websocket, context_id, html,
device_address = await setup_granted_device(websocket, context_id, url,
[service_uuid])
await create_gatt_connection(websocket, context_id)
await simulate_service(websocket, context_id, device_address, service_uuid,
Expand Down Expand Up @@ -84,9 +90,9 @@ async def teardown(websocket, context_id):


@pytest.mark.asyncio
async def test_bluetooth_simulateService(websocket, context_id, html):
async def test_bluetooth_simulateService(websocket, context_id, url_bad_ssl):
device_address = await setup_granted_device(
websocket, context_id, html,
websocket, context_id, url_bad_ssl,
[HEART_RATE_SERVICE_UUID, BATTERY_SERVICE_UUID])
await create_gatt_connection(websocket, context_id)
await simulate_service(websocket, context_id, device_address,
Expand Down Expand Up @@ -252,8 +258,9 @@ async def test_bluetooth_add_descriptor_to_unknown_characteristic(


@pytest.mark.asyncio
async def test_bluetooth_descriptor_write_event(websocket, context_id, html):
await setup_descriptor(websocket, context_id, html,
async def test_bluetooth_descriptor_write_event(websocket, context_id,
url_bad_ssl):
await setup_descriptor(websocket, context_id, url_bad_ssl,
HEART_RATE_SERVICE_UUID,
MEASUREMENT_INTERVAL_CHARACTERISTIC_UUID,
{'write': True},
Expand Down Expand Up @@ -306,8 +313,9 @@ async def test_bluetooth_descriptor_write_event(websocket, context_id, html):


@pytest.mark.asyncio
async def test_bluetooth_descriptor_read_event(websocket, context_id, html):
await setup_descriptor(websocket, context_id, html,
async def test_bluetooth_descriptor_read_event(websocket, context_id,
url_bad_ssl):
await setup_descriptor(websocket, context_id, url_bad_ssl,
HEART_RATE_SERVICE_UUID,
MEASUREMENT_INTERVAL_CHARACTERISTIC_UUID,
{'read': True},
Expand Down
16 changes: 11 additions & 5 deletions tests/bluetooth/test_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from . import (FAKE_DEVICE_ADDRESS, FAKE_DEVICE_NAME, disable_simulation,
request_device, setup_device)

# Bluetooth require secure context (either `Secure` or `SecureLocalhost`).
pytestmark = pytest.mark.parametrize('capabilities', [{
'acceptInsecureCerts': True
}],
indirect=True)


@pytest_asyncio.fixture(autouse=True)
async def teardown(websocket, context_id):
Expand Down Expand Up @@ -54,9 +60,9 @@ async def test_simulate_create_adapter_twice(websocket, context_id, state_1,

@pytest.mark.asyncio
async def test_bluetooth_requestDevicePromptUpdated(websocket, context_id,
html):
url_bad_ssl):
await subscribe(websocket, ['bluetooth'])
await goto_url(websocket, context_id, html())
await goto_url(websocket, context_id, url_bad_ssl)
await setup_device(websocket, context_id)
await request_device(websocket, context_id)
response = await wait_for_event(websocket,
Expand All @@ -75,10 +81,10 @@ async def test_bluetooth_requestDevicePromptUpdated(websocket, context_id,

@pytest.mark.asyncio
@pytest.mark.parametrize('accept', [True, False])
async def test_bluetooth_handleRequestDevicePrompt(websocket, context_id, html,
accept):
async def test_bluetooth_handleRequestDevicePrompt(websocket, context_id,
url_bad_ssl, accept):
await subscribe(websocket, ['bluetooth'])
await goto_url(websocket, context_id, html())
await goto_url(websocket, context_id, url_bad_ssl)
await setup_device(websocket, context_id)
await request_device(websocket, context_id)
event = await wait_for_event(websocket,
Expand Down
10 changes: 8 additions & 2 deletions tests/bluetooth/test_gatt_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

from . import disable_simulation, setup_granted_device

# Bluetooth require secure context (either `Secure` or `SecureLocalhost`).
pytestmark = pytest.mark.parametrize('capabilities', [{
'acceptInsecureCerts': True
}],
indirect=True)


async def is_gatt_connected(websocket, context_id: str) -> bool:
response = await execute_command(
Expand All @@ -46,9 +52,9 @@ async def teardown(websocket, context_id):
@pytest.mark.asyncio
@pytest.mark.parametrize('code', [0x0, 0x1, 0x2])
async def test_bluetooth_simulateGattConnectionResponse(
websocket, context_id, html, code):
websocket, context_id, url_bad_ssl, code):
await subscribe(websocket, ['bluetooth.gattConnectionAttempted'])
await setup_granted_device(websocket, context_id, html)
await setup_granted_device(websocket, context_id, url_bad_ssl)

await send_JSON_command(
websocket, {
Expand Down
16 changes: 11 additions & 5 deletions tests/bluetooth/test_handle_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from . import (FAKE_DEVICE_ADDRESS, disable_simulation, request_device,
setup_device)

# Bluetooth require secure context (either `Secure` or `SecureLocalhost`).
pytestmark = pytest.mark.parametrize('capabilities', [{
'acceptInsecureCerts': True
}],
indirect=True)


@pytest_asyncio.fixture(autouse=True)
async def teardown(websocket, context_id):
Expand All @@ -30,9 +36,9 @@ async def teardown(websocket, context_id):

@pytest.mark.asyncio
async def test_bluetooth_requestDevicePromptUpdated(websocket, context_id,
html):
url_bad_ssl):
await subscribe(websocket, ['bluetooth.requestDevicePromptUpdated'])
await goto_url(websocket, context_id, html())
await goto_url(websocket, context_id, url_bad_ssl)
await setup_device(websocket, context_id)
await request_device(websocket, context_id)
response = await wait_for_event(websocket,
Expand All @@ -51,10 +57,10 @@ async def test_bluetooth_requestDevicePromptUpdated(websocket, context_id,

@pytest.mark.asyncio
@pytest.mark.parametrize('accept', [True, False])
async def test_bluetooth_handleRequestDevicePrompt(websocket, context_id, html,
accept):
async def test_bluetooth_handleRequestDevicePrompt(websocket, context_id,
url_bad_ssl, accept):
await subscribe(websocket, ['bluetooth'])
await goto_url(websocket, context_id, html())
await goto_url(websocket, context_id, url_bad_ssl)
await setup_device(websocket, context_id)
await request_device(websocket, context_id)
event = await wait_for_event(websocket,
Expand Down
10 changes: 8 additions & 2 deletions tests/bluetooth/test_service_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
disable_simulation, setup_device, setup_granted_device,
simulate_service)

# Bluetooth require secure context (either `Secure` or `SecureLocalhost`).
pytestmark = pytest.mark.parametrize('capabilities', [{
'acceptInsecureCerts': True
}],
indirect=True)


async def get_services(websocket, context_id: str) -> list[str]:
response = await execute_command(
Expand Down Expand Up @@ -58,9 +64,9 @@ async def teardown(websocket, context_id):


@pytest.mark.asyncio
async def test_bluetooth_simulateService(websocket, context_id, html):
async def test_bluetooth_simulateService(websocket, context_id, url_bad_ssl):
device_address = await setup_granted_device(
websocket, context_id, html,
websocket, context_id, url_bad_ssl,
[HEART_RATE_SERVICE_UUID, BATTERY_SERVICE_UUID])
await create_gatt_connection(websocket, context_id)

Expand Down
Binary file removed tests/browsing_context/capture_screenshot/oopif.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ async def test_screenshot_element(websocket, context_id, query_selector, html):


@pytest.mark.asyncio
@pytest.mark.skip(reason="TODO: fails on CI")
async def test_screenshot_oopif(websocket, context_id, html, iframe):
await goto_url(websocket,
context_id,
html(iframe("https://www.example.com")),
html(iframe(html("OOPIF", same_origin=False))),
wait="complete")

iframe_context_id = (await get_tree(
Expand All @@ -135,7 +134,7 @@ async def test_screenshot_oopif(websocket, context_id, html, iframe):
})
await read_JSON_message(websocket)

await send_JSON_command(
command_id = await send_JSON_command(
websocket, {
"method": "browsingContext.captureScreenshot",
"params": {
Expand All @@ -144,14 +143,12 @@ async def test_screenshot_oopif(websocket, context_id, html, iframe):
})

resp = await read_JSON_message(websocket)
assert resp["result"] == {'data': ANY_STR}

png_filename = "oopif.png"
with open(Path(__file__).parent.resolve() / png_filename,
'rb') as image_file:
png_base64 = base64.b64encode(image_file.read()).decode('utf-8')

assert_images_similar(resp["result"]["data"], png_base64)
assert resp == {
'error': 'unsupported operation',
'id': command_id,
'message': ANY_STR,
'type': 'error',
}


@pytest.mark.asyncio
Expand Down
Loading
Loading