|
15 | 15 | InvalidArgumentException,
|
16 | 16 | NoSuchFrameException,
|
17 | 17 | NoSuchInterceptException,
|
| 18 | + NoSuchNetworkCollectorException, |
18 | 19 | NoSuchRequestException,
|
19 | 20 | NoSuchScriptException,
|
20 | 21 | NoSuchUserContextException,
|
@@ -736,6 +737,44 @@ async def on_event(method, data, event=event):
|
736 | 737 | remove_listener()
|
737 | 738 |
|
738 | 739 |
|
| 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 | + |
739 | 778 | @pytest_asyncio.fixture
|
740 | 779 | async def add_intercept(bidi_session):
|
741 | 780 | """Add a network intercept for the provided phases and url patterns, and
|
|
0 commit comments