Skip to content

Commit ede6f34

Browse files
juliandescottesmoz-wptsync-bot
authored andcommitted
[wdspec] Add fixture to add network data collector
Depends on D259969 Differential Revision: https://phabricator.services.mozilla.com/D259538 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1971780 gecko-commit: 8f9e6b10369b0fe0c9e00fffae88bec4bd6a2b78 gecko-reviewers: webdriver-reviewers, Sasha
1 parent ac28854 commit ede6f34

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

webdriver/tests/support/fixtures_bidi.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
InvalidArgumentException,
1616
NoSuchFrameException,
1717
NoSuchInterceptException,
18+
NoSuchNetworkCollectorException,
1819
NoSuchRequestException,
1920
NoSuchScriptException,
2021
NoSuchUserContextException,
@@ -736,6 +737,44 @@ async def on_event(method, data, event=event):
736737
remove_listener()
737738

738739

740+
@pytest_asyncio.fixture
741+
async def add_data_collector(bidi_session):
742+
"""Add a network data collector, and ensure the collector is removed at the
743+
end of the test."""
744+
745+
collectors = []
746+
747+
async def add_data_collector(
748+
collector_type="blob",
749+
data_types=["response"],
750+
max_encoded_data_size=1000,
751+
contexts=None,
752+
user_contexts=None,
753+
):
754+
nonlocal collectors
755+
collector = await bidi_session.network.add_data_collector(
756+
collector_type=collector_type,
757+
data_types=data_types,
758+
max_encoded_data_size=max_encoded_data_size,
759+
contexts=contexts,
760+
user_contexts=user_contexts,
761+
)
762+
collectors.append(collector)
763+
764+
return collector
765+
766+
yield add_data_collector
767+
768+
# Remove all added collectors at the end of the test
769+
for collector in collectors:
770+
try:
771+
await bidi_session.network.remove_data_collector(collector=collector)
772+
except NoSuchNetworkCollectorException:
773+
# Ignore exceptions in case a specific collector was already removed
774+
# during the test.
775+
pass
776+
777+
739778
@pytest_asyncio.fixture
740779
async def add_intercept(bidi_session):
741780
"""Add a network intercept for the provided phases and url patterns, and

0 commit comments

Comments
 (0)