Bug 1694143 - [remote] Add wdspec tests for log.entryAdded r=webdriver-reviewers,whimboo

Depends on D124834

Differential Revision: https://phabricator.services.mozilla.com/D122529
This commit is contained in:
Julian Descottes 2021-09-09 20:38:00 +00:00
Родитель 4c89478a70
Коммит 52eb0ef956
5 изменённых файлов: 86 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,3 @@
[console.py]
disabled:
if release_or_beta: https://bugzilla.mozilla.org/show_bug.cgi?id=1712902

Просмотреть файл

@ -0,0 +1,67 @@
import pytest
@pytest.mark.asyncio
@pytest.mark.parametrize("log_argument, expected_text", [
("'TEST'", "TEST"),
("'TWO', 'PARAMETERS'", "TWO PARAMETERS"),
("{}", "[object Object]"),
("['1', '2', '3']", "1,2,3"),
("null, undefined", "null undefined"),
], ids=[
'single string',
'two strings',
'empty object',
'array of strings',
'null and undefined',
])
async def test_console_log_argument_type(bidi_session,
current_session,
wait_for_event,
log_argument,
expected_text):
await bidi_session.session.subscribe(events=["log.entryAdded"])
on_entry_added = wait_for_event("log.entryAdded")
# TODO: To be replaced with the BiDi implementation of execute_script.
current_session.execute_script(f"console.log({log_argument})")
event_data = await on_entry_added
assert event_data['text'] == expected_text
@pytest.mark.asyncio
@pytest.mark.parametrize("log_method, expected_level", [
("assert", "error"),
("debug", "debug"),
("error", "error"),
("info", "info"),
("log", "info"),
("table", "info"),
("trace", "debug"),
("warn", "warning"),
])
async def test_console_log_level(bidi_session,
current_session,
wait_for_event,
log_method,
expected_level):
await bidi_session.session.subscribe(events=["log.entryAdded"])
on_entry_added = wait_for_event("log.entryAdded")
# TODO: To be replaced with the BiDi implementation of execute_script.
if log_method == 'assert':
# assert has to be called with a first falsy argument to trigger a log.
current_session.execute_script("console.assert(false, 'text')")
else:
current_session.execute_script(f"console.{log_method}('text')")
event_data = await on_entry_added
assert event_data['text'] == 'text'
assert event_data['level'] == expected_level
assert event_data['type'] == 'console'
assert event_data['method'] == log_method
assert isinstance(event_data['timestamp'], int)

Просмотреть файл

@ -1,5 +1,4 @@
import pytest import pytest
import asyncio
import websockets import websockets
import webdriver import webdriver

Просмотреть файл

@ -1,5 +1,3 @@
import asyncio
import pytest import pytest
from webdriver.bidi.error import InvalidArgumentException from webdriver.bidi.error import InvalidArgumentException

Просмотреть файл

@ -12,3 +12,19 @@ def send_blocking_command(bidi_session):
future_response = await bidi_session.send_command(command, params) future_response = await bidi_session.send_command(command, params)
return await future_response return await future_response
return send_blocking_command return send_blocking_command
@pytest.fixture
def wait_for_event(bidi_session, event_loop):
"""Wait until the BiDi session emits an event and resolve the event data."""
def wait_for_event(event_name: str):
future = event_loop.create_future()
async def on_event(method, data):
remove_listener()
future.set_result(data)
remove_listener = bidi_session.add_event_listener(event_name, on_event)
return future
return wait_for_event