Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Remove not needed tests
Magnus Müller16e64ad42b82
diff --git a/tests/ci/test_browser_event_NavigateToUrlEvent2.py b/tests/ci/test_browser_event_NavigateToUrlEvent2.pydeleted file mode 100644index 7c47fe30c..000000000--- a/tests/ci/test_browser_event_NavigateToUrlEvent2.py+++ /dev/null@@ -1,379 +0,0 @@-"""Test navigation events are emitted properly in all cases."""--import asyncio-import time-from typing import cast--import pytest--from browser_use.browser.events import (- ClickElementEvent,- NavigateToUrlEvent,- NavigationCompleteEvent,- NavigationStartedEvent,- TabCreatedEvent,-)-from browser_use.browser.profile import BrowserProfile-from browser_use.browser.session import BrowserSession---async def test_navigation_events_fast_page_load(httpserver):- """Test navigation events for page that loads easily/normally within 1s."""- # Set up a fast endpoint- httpserver.expect_request('/fast').respond_with_data(- '<html><head><title>Fast Page</title></head><body><h1>Fast Loading Page</h1></body></html>',- status=200,- content_type='text/html',- )- fast_url = httpserver.url_for('/fast')-- profile = BrowserProfile(headless=True)- session = BrowserSession(browser_profile=profile)-- # Track navigation events- navigation_started_events = []- navigation_complete_events = []- session.event_bus.on(NavigationStartedEvent, lambda e: navigation_started_events.append(e))- session.event_bus.on(NavigationCompleteEvent, lambda e: navigation_complete_events.append(e))-- try:- # Start browser- await session.start()-- # Navigate to fast page- start_time = time.time()- session.event_bus.dispatch(NavigateToUrlEvent(url=fast_url))-- # Wait for navigation to complete- nav_complete: NavigationCompleteEvent = cast(- NavigationCompleteEvent, await session.event_bus.expect(NavigationCompleteEvent, timeout=5.0)- )- end_time = time.time()-- # Verify navigation completed in reasonable time (within 5s)- assert (end_time - start_time) < 5.0, 'Navigation should complete in reasonable time'-- # Verify NavigationStartedEvent was emitted- assert len(navigation_started_events) >= 1, 'Should have NavigationStartedEvent'- nav_started = navigation_started_events[-1]- assert nav_started.url == fast_url- assert nav_started.target_id is not None-- # Verify NavigationCompleteEvent was emitted with success- assert len(navigation_complete_events) >= 1, 'Should have NavigationCompleteEvent'- assert nav_complete.url == fast_url- assert nav_complete.target_id- # CDP doesn't provide HTTP status directly, just check no error- assert nav_complete.error_message is None, 'Should have no error message'- assert nav_complete.loading_status is None, 'Should have no loading status issues'-- finally:- await session.stop()---async def test_navigation_events_slow_page_with_timeout(httpserver):- """Test navigation events for page that takes >10s to load and times out."""-- # Set up a slow endpoint that takes longer than we want to wait- def slow_handler(request):- time.sleep(5.0) # 5 seconds - longer than our timeout- from werkzeug import Response-- return Response('<html><body>Finally loaded</body></html>', status=200)-- httpserver.expect_request('/slow').respond_with_handler(slow_handler)- slow_url = httpserver.url_for('/slow')-- # Create profile with shorter timeout for faster testing- profile = BrowserProfile(- headless=True,- wait_for_network_idle_page_load_time=0.5, # 0.5 second network idle- )- session = BrowserSession(browser_profile=profile)-- # Track navigation events- navigation_started_events = []- navigation_complete_events = []- session.event_bus.on(NavigationStartedEvent, lambda e: navigation_started_events.append(e))- session.event_bus.on(NavigationCompleteEvent, lambda e: navigation_complete_events.append(e))-- try:- # Start browser- await session.start()-- # Navigate to slow page- session.event_bus.dispatch(NavigateToUrlEvent(url=slow_url))-- # Wait for navigation to timeout and complete with error- nav_complete: NavigationCompleteEvent = cast(- NavigationCompleteEvent, await session.event_bus.expect(NavigationCompleteEvent, timeout=10.0)- )-- # Verify NavigationStartedEvent was emitted- assert len(navigation_started_events) >= 1, 'Should have NavigationStartedEvent'- nav_started = navigation_started_events[-1]- assert nav_started.url == slow_url-- # Verify NavigationCompleteEvent was emitted- assert len(navigation_complete_events) >= 1, 'Should have NavigationCompleteEvent'- assert nav_complete.url == slow_url-- # Either the navigation succeeded after timeout (page loaded) or it timed out- # Both are valid outcomes - what matters is that NavigationCompleteEvent was emitted- if nav_complete.error_message or nav_complete.loading_status:- # Navigation had issues (timeout/loading problems)- has_timeout_indicator = (- nav_complete.error_message- and ('timeout' in nav_complete.error_message.lower() or 'pending' in nav_complete.error_message.lower())- or nav_complete.loading_status- and (- 'aborted' in nav_complete.loading_status.lower()- or 'pending' in nav_complete.loading_status.lower()- or 'requests' in nav_complete.loading_status.lower()- )- )- print(- f"Navigation had issues - error_message: '{nav_complete.error_message}', loading_status: '{nav_complete.loading_status}'"- )- assert has_timeout_indicator, (- f'Should indicate timeout/loading issues when navigation has problems. '- f"error_message='{nav_complete.error_message}', "- f"loading_status='{nav_complete.loading_status}'"- )- else:- # Navigation succeeded (slow but successful)- print('Navigation succeeded despite being slow')- # CDP doesn't provide HTTP status directly, just check no error- assert nav_complete.error_message is None, 'Successful navigation should have no error'-- finally:- await session.stop()--[email protected](reason='DOM element detection issue - same-tab-link not found in selector map')-async def test_navigation_events_link_clicks(httpserver):- """Test that clicking links (same tab and new tab) triggers NavigationCompleteEvent."""- # Set up pages with different types of links- main_page = """- <html>- <head><title>Link Test</title></head>- <body>- <h1>Link Click Test</h1>- <a id="same-tab-link" href="/target-page">Same Tab Link</a>- <a id="new-tab-link" href="/target-page" target="_blank">New Tab Link</a>- <a id="js-navigation" href="#" onclick="window.location.href='/js-target'; return false;">JS Navigation</a>- </body>- </html>- """-- target_page = """- <html>- <head><title>Target Page</title></head>- <body><h1>Target Page Loaded</h1></body>- </html>- """-- js_target_page = """- <html>- <head><title>JS Target</title></head>- <body><h1>JavaScript Navigation Target</h1></body>- </html>- """-- httpserver.expect_request('/link-test').respond_with_data(main_page, status=200, content_type='text/html')- httpserver.expect_request('/target-page').respond_with_data(target_page, status=200, content_type='text/html')- httpserver.expect_request('/js-target').respond_with_data(js_target_page, status=200, content_type='text/html')-- main_url = httpserver.url_for('/link-test')- target_url = httpserver.url_for('/target-page')- js_target_url = httpserver.url_for('/js-target')-- profile = BrowserProfile(headless=True)- session = BrowserSession(browser_profile=profile)-- # Track navigation and tab events- navigation_complete_events = []- tab_created_events = []- session.event_bus.on(NavigationCompleteEvent, lambda e: navigation_complete_events.append(e))- session.event_bus.on(TabCreatedEvent, lambda e: tab_created_events.append(e))-- try:- # Start browser- await session.start()-- # Navigate to the main page- session.event_bus.dispatch(NavigateToUrlEvent(url=main_url))- await session.event_bus.expect(NavigationCompleteEvent, timeout=5.0)-- # Clear events to focus on link clicks- navigation_complete_events.clear()-- # Test 1: Same tab link click- state = await session.get_browser_state_summary()- same_tab_link_found = False-- for idx, element in state.dom_state.selector_map.items():- if hasattr(element, 'attributes') and element.attributes.get('id') == 'same-tab-link':- same_tab_link_found = True- click_element = await session.get_dom_element_by_index(idx)- if click_element is not None:- session.event_bus.dispatch(ClickElementEvent(node=click_element))- break-- assert same_tab_link_found, f'Should find same tab link {main_url}'-- # Wait for navigation to complete- nav_complete: NavigationCompleteEvent = cast(- NavigationCompleteEvent, await session.event_bus.expect(NavigationCompleteEvent, timeout=5.0)- )-- assert nav_complete.url == target_url, f'Should navigate to {target_url}'- assert nav_complete.error_message is None, 'Link navigation should succeed'-- # Test 2: New tab link click (if supported)- # Navigate back to main page first- session.event_bus.dispatch(NavigateToUrlEvent(url=main_url))- await session.event_bus.expect(NavigationCompleteEvent, timeout=5.0)-- # Clear events- navigation_complete_events.clear()- tab_created_events.clear()-- state = await session.get_browser_state_summary()- new_tab_link_found = False-- for idx, element in state.dom_state.selector_map.items():- if hasattr(element, 'attributes') and element.attributes.get('id') == 'new-tab-link':- new_tab_link_found = True- click_element = await session.get_dom_element_by_index(idx)- if click_element is not None:- session.event_bus.dispatch(ClickElementEvent(node=click_element))- break-- if new_tab_link_found:- # Wait for either new tab creation or navigation- await asyncio.sleep(2.0) # Give time for tab creation and navigation-- # Should have either tab creation or navigation event (or both)- has_new_tab_activity = len(tab_created_events) > 0 or len(navigation_complete_events) > 0- assert has_new_tab_activity, 'New tab link should trigger tab creation or navigation'-- if navigation_complete_events:- nav_complete = navigation_complete_events[-1]- assert target_url in nav_complete.url or nav_complete.error_message is None-- # Test 3: JavaScript navigation- session.event_bus.dispatch(NavigateToUrlEvent(url=main_url))- await session.event_bus.expect(NavigationCompleteEvent, timeout=5.0)-- navigation_complete_events.clear()-- state = await session.get_browser_state_summary()- js_link_found = False-- for idx, element in state.dom_state.selector_map.items():- if hasattr(element, 'attributes') and element.attributes.get('id') == 'js-navigation':- js_link_found = True- click_element = await session.get_dom_element_by_index(idx)- if click_element is not None:- session.event_bus.dispatch(ClickElementEvent(node=click_element))- break-- if js_link_found:- # Wait for JavaScript navigation to complete- nav_complete = cast(NavigationCompleteEvent, await session.event_bus.expect(NavigationCompleteEvent, timeout=5.0))-- assert nav_complete.url == js_target_url, 'JS navigation should work'- assert nav_complete.error_message is None, 'JS navigation should succeed'-- finally:- await session.stop()---# @pytest.mark.asyncio-# async def test_navigation_timeout_event_dispatch():-# """Test that NavigateToUrlEvent with timeout_ms properly dispatches NavigationCompleteEvent on timeout."""-# profile = BrowserProfile(headless=True)-# session = BrowserSession(browser_profile=profile)--# # Track navigation events-# navigation_complete_events = []-# session.event_bus.on(NavigationCompleteEvent, lambda e: navigation_complete_events.append(e))--# try:-# # Start browser-# await session.start()--# # Navigate with a very short timeout to a valid but slow URL-# session.event_bus.dispatch(-# NavigateToUrlEvent(-# url='data:text/html,<h1>Should timeout</h1>', # Use a data URL that should work-# timeout_ms=1, # 1ms timeout - should definitely timeout-# )-# )--# # Wait for navigation to timeout and complete with error-# nav_complete: NavigationCompleteEvent = cast(-# NavigationCompleteEvent, await session.event_bus.expect(NavigationCompleteEvent, timeout=5.0)-# )--# # Verify NavigationCompleteEvent indicates timeout-# assert nav_complete.error_message is not None, 'Should have error message for timeout'-# assert 'timed out' in nav_complete.error_message.lower(), f'Error should mention timed out: {nav_complete.error_message}'-# assert nav_complete.loading_status is not None, 'Should have loading status'-# assert 'timeout' in nav_complete.loading_status.lower(), (-# f'Loading status should mention timeout: {nav_complete.loading_status}'-# )--# # Verify specific timeout details-# assert '1ms' in nav_complete.error_message, 'Should mention the specific timeout duration'--# finally:-# await session.stop()---# @pytest.mark.asyncio-# async def test_navigation_error_recovery():-# """Test that navigation errors are properly reported and don't break subsequent navigation."""-# profile = BrowserProfile(headless=True)-# session = BrowserSession(browser_profile=profile)--# # Track navigation events-# navigation_complete_events = []-# session.event_bus.on(NavigationCompleteEvent, lambda e: navigation_complete_events.append(e))--# try:-# # Start browser-# await session.start()--# # Try to navigate to invalid URL-# session.event_bus.dispatch(NavigateToUrlEvent(url='invalid://not-a-real-url'))--# # Wait for navigation to fail-# nav_complete: NavigationCompleteEvent = cast(-# NavigationCompleteEvent, await session.event_bus.expect(NavigationCompleteEvent, timeout=5.0)-# )--# # Verify NavigationCompleteEvent indicates error-# assert nav_complete.error_message is not None, 'Should have error message for invalid URL'-# assert nav_complete.url == 'invalid://not-a-real-url'--# # Clear events-# navigation_complete_events.clear()--# # Verify that subsequent navigation still works-# session.event_bus.dispatch(NavigateToUrlEvent(url='data:text/html,<h1>Recovery Test</h1>'))--# nav_complete_recovery: NavigationCompleteEvent = cast(-# NavigationCompleteEvent, await session.event_bus.expect(NavigationCompleteEvent, timeout=5.0)-# )--# # Verify recovery navigation succeeded-# assert nav_complete_recovery.url == 'data:text/html,<h1>Recovery Test</h1>'-# assert nav_complete_recovery.error_message is None, 'Recovery navigation should succeed'--# finally:-# await session.stop()diff --git a/tests/ci/test_browser_session_recent_events.py b/tests/ci/test_browser_session_recent_events.pydeleted file mode 100644index 673ee0d3a..000000000--- a/tests/ci/test_browser_session_recent_events.py+++ /dev/null@@ -1,355 +0,0 @@-"""-Test browser session recent events tracking functionality.-"""--import json-import time--import pytest-from pytest_httpserver import HTTPServer-from werkzeug.wrappers import Response--from browser_use.browser import BrowserProfile, BrowserSession-from browser_use.browser.events import NavigateToUrlEvent, ScreenshotEvent---class TestBrowserRecentEvents:- """Test recent events tracking functionality"""-- async def test_recent_events_on_successful_load(self, httpserver: HTTPServer):- """Test that recent events shows successful navigation when page loads successfully"""- # Set up a simple page that loads quickly- httpserver.expect_request('/fast').respond_with_data(- '<html><head><title>Fast Page</title></head><body><h1>Quick loading page</h1></body></html>',- content_type='text/html',- )-- browser_session = BrowserSession(- browser_profile=BrowserProfile(- headless=True,- user_data_dir=None,- keep_alive=False,- )- )-- try:- await browser_session.start()-- # Navigate to the fast-loading page- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=httpserver.url_for('/fast')))- await event- await event.event_result(raise_if_any=True, raise_if_none=False)-- # Get browser state with recent events- state = await browser_session.get_browser_state_summary(include_recent_events=True)-- # Recent events should show successful navigation- assert state.recent_events is not None-- # Parse JSON and verify events- events = json.loads(state.recent_events)- event_types = [e.get('event_type') for e in events]-- # Should have navigation events- assert 'NavigationCompleteEvent' in event_types, 'Should have NavigationCompleteEvent'-- # Check the navigation was successful (no errors)- nav_events = [e for e in events if e.get('event_type') == 'NavigationCompleteEvent']- last_nav = nav_events[-1]- assert last_nav.get('error_message') is None, 'Should not have error message'- # Note: CDP doesn't provide HTTP status directly, so skip status check-- finally:- await browser_session.kill()-- # async def test_recent_events_tracks_multiple_navigations(self, httpserver: HTTPServer):- # """Test that recent events properly tracks multiple navigations"""- # # Set up pages- # slow_html = """- # <html>- # <head>- # <title>Slow Page</title>- # <script src="/slow.js"></script>- # </head>- # <body><h1>Slow page</h1></body>- # </html>- # """-- # httpserver.expect_request('/slow').respond_with_data(slow_html, content_type='text/html')-- # def slow_handler(req):- # time.sleep(5)- # return Response('slow')-- # httpserver.expect_request('/slow.js').respond_with_handler(slow_handler)-- # httpserver.expect_request('/fast').respond_with_data(- # '<html><head><title>Fast Page</title></head><body><h1>Fast page</h1></body></html>',- # content_type='text/html',- # )-- # browser_session = BrowserSession(- # browser_profile=BrowserProfile(- # headless=True,- # user_data_dir=None,- # keep_alive=False,- # )- # )-- # try:- # await browser_session.start()-- # # Navigate to slow page- # event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=httpserver.url_for('/slow')))- # await event- # await event.event_result(raise_if_any=True, raise_if_none=False)- # state1 = await browser_session.get_browser_state_summary(include_recent_events=True)- # assert state1.recent_events is not None- # events1 = json.loads(state1.recent_events)- # event_types1 = [e.get('event_type') for e in events1]- # assert 'NavigationCompleteEvent' in event_types1 or 'NavigateToUrlEvent' in event_types1-- # # Navigate to fast page- # event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=httpserver.url_for('/fast')))- # await event- # await event.event_result(raise_if_any=True, raise_if_none=False)- # state2 = await browser_session.get_browser_state_summary()-- # # Recent events should show both navigations- # assert state2.recent_events is not None- # events2 = json.loads(state2.recent_events)-- # # Count navigation events (last 10 events should include both)- # nav_complete_count = sum(1 for e in events2 if e.get('event_type') == 'NavigationCompleteEvent')- # nav_url_count = sum(1 for e in events2 if e.get('event_type') == 'NavigateToUrlEvent')-- # # Should have events from both navigations- # assert nav_complete_count >= 1 or nav_url_count >= 2, 'Recent events should show multiple navigation attempts'-- # finally:- # await browser_session.kill()-- async def test_recent_events_preserved_in_minimal_state(self, httpserver: HTTPServer):- """Test that recent events is preserved even when falling back to minimal state"""- # Create a page that causes DOM processing to fail- malformed_html = """- <html>- <head>- <title>Malformed Page</title>- <script src="/slow.js"></script>- <script>- // This might cause DOM processing issues- Object.defineProperty(document, 'querySelectorAll', {- get() { throw new Error('DOM processing blocked'); }- });- </script>- </head>- <body><h1>Page with DOM issues</h1></body>- </html>- """-- httpserver.expect_request('/malformed').respond_with_data(malformed_html, content_type='text/html')-- def slow_handler(req):- time.sleep(5)- return Response('slow')-- httpserver.expect_request('/slow.js').respond_with_handler(slow_handler)-- browser_session = BrowserSession(- browser_profile=BrowserProfile(- headless=True,- user_data_dir=None,- keep_alive=False,- )- )-- try:- await browser_session.start()-- # Navigate to the malformed page- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=httpserver.url_for('/malformed')))- await event- await event.event_result(raise_if_any=True, raise_if_none=False)-- # Get browser state - this might fall back to minimal state- state = await browser_session.get_browser_state_summary(include_recent_events=True)-- # Even if we get minimal state, recent events should be preserved- assert state.recent_events is not None- events = json.loads(state.recent_events)- assert len(events) > 0, 'Should have events even in minimal state'-- # Should have navigation attempt- event_types = [e.get('event_type') for e in events]- assert 'NavigateToUrlEvent' in event_types or 'NavigationCompleteEvent' in event_types, (- 'Should have navigation events even in minimal state'- )-- finally:- await browser_session.kill()-- @pytest.mark.parametrize('timeout_seconds', [0.5, 1.0, 2.0])- async def test_recent_events_with_different_timeouts(self, httpserver: HTTPServer, timeout_seconds: float):- """Test that recent events captures navigation with different timeout configurations"""- # Set up a slow page- httpserver.expect_request(f'/timeout_{timeout_seconds}').respond_with_data(- f'<html><head><title>Timeout Test {timeout_seconds}s</title>'- f'<script src="/slow_{timeout_seconds}.js"></script></head>'- f'<body><h1>Testing {timeout_seconds}s timeout</h1></body></html>',- content_type='text/html',- )-- def very_slow_handler(req):- time.sleep(10)- return Response('slow')-- httpserver.expect_request(f'/slow_{timeout_seconds}.js').respond_with_handler(very_slow_handler)-- browser_session = BrowserSession(- browser_profile=BrowserProfile(- headless=True,- user_data_dir=None,- keep_alive=False,- wait_for_network_idle_page_load_time=0.1,- minimum_wait_page_load_time=0.1,- )- )-- try:- await browser_session.start()-- # Navigate to the page- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=httpserver.url_for(f'/timeout_{timeout_seconds}')))- await event- await event.event_result(raise_if_any=True, raise_if_none=False)-- # Get browser state with recent events- state = await browser_session.get_browser_state_summary(include_recent_events=True)-- # Verify recent events captured the navigation- assert state.recent_events is not None- events = json.loads(state.recent_events)- event_types = [e.get('event_type') for e in events]-- # Should have navigation events regardless of timeout- assert 'NavigateToUrlEvent' in event_types or 'NavigationCompleteEvent' in event_types, (- f'Should have navigation events for {timeout_seconds}s timeout'- )-- # If navigation completed with error, it might mention timeout- nav_complete_events = [e for e in events if e.get('event_type') == 'NavigationCompleteEvent']- if nav_complete_events and nav_complete_events[-1].get('error_message'):- print(f'Navigation error for {timeout_seconds}s timeout: {nav_complete_events[-1].get("error_message")}')-- finally:- await browser_session.kill()---class TestEventHistoryInfrastructure:- """Tests for NEW event history tracking infrastructure only."""-- async def test_event_bus_history_tracking(self, httpserver: HTTPServer):- """Test that event bus properly tracks event history."""- browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True, user_data_dir=None, keep_alive=False))-- try:- await browser_session.start()- initial_history_count = len(browser_session.event_bus.event_history)-- # Set up test page- httpserver.expect_request('/history-test').respond_with_data(- '<html><body><h1>Event History Test</h1></body></html>',- content_type='text/html',- )-- # Perform actions that generate events- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=httpserver.url_for('/history-test')))- await event- await event.event_result(raise_if_any=True, raise_if_none=False)- screenshot_event = browser_session.event_bus.dispatch(ScreenshotEvent())- await screenshot_event- await screenshot_event.event_result(raise_if_any=True, raise_if_none=False)-- # Verify event history has grown- final_history_count = len(browser_session.event_bus.event_history)- assert final_history_count > initial_history_count, 'Event history should track new events'-- # Verify events are stored properly- for event_id, event in browser_session.event_bus.event_history.items():- assert event_id is not None- assert event is not None- assert hasattr(event, 'event_type') or hasattr(event, '__class__')-- finally:- await browser_session.kill()-- async def test_generate_recent_events_summary_format(self, httpserver: HTTPServer):- """Test that _generate_recent_events_summary produces valid JSON."""- browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True, user_data_dir=None, keep_alive=False))-- try:- await browser_session.start()-- # Generate some events- httpserver.expect_request('/json-test').respond_with_data(- '<html><body><h1>JSON Test</h1></body></html>',- content_type='text/html',- )- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=httpserver.url_for('/json-test')))- await event- await event.event_result(raise_if_any=True, raise_if_none=False)-- # Test the NEW method _generate_recent_events_summary- recent_events_json = await browser_session.get_browser_state_summary(include_recent_events=True)- recent_events_json = recent_events_json.recent_events- assert recent_events_json is not None-- # Should return valid JSON- assert recent_events_json != '[]', 'Should have events'- events = json.loads(recent_events_json) # Should not raise JSON decode error- assert isinstance(events, list), 'Should return a list of events'-- # Events should exclude problematic fields like 'state'- for event in events:- assert isinstance(event, dict), 'Each event should be a dict'- assert 'state' not in event, "Event should not contain 'state' field (circular reference)"-- finally:- await browser_session.kill()-- async def test_event_history_limits(self, httpserver: HTTPServer):- """Test that event history summary respects max_events parameter."""- browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True, user_data_dir=None, keep_alive=False))-- try:- await browser_session.start()-- # Generate multiple events- httpserver.expect_request('/limit-test').respond_with_data(- '<html><body><h1>Limit Test</h1></body></html>',- content_type='text/html',- )-- # Perform multiple actions to generate events- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=httpserver.url_for('/limit-test')))- await event- await event.event_result(raise_if_any=True, raise_if_none=False)- screenshot_event = browser_session.event_bus.dispatch(ScreenshotEvent())- await screenshot_event- await screenshot_event.event_result(raise_if_any=True, raise_if_none=False)- await browser_session.get_tabs()-- # Test recent events summary via BrowserStateSummary- state_with_events = await browser_session.get_browser_state_summary(include_recent_events=True)- assert state_with_events.recent_events is not None-- # Parse the JSON events- events = json.loads(state_with_events.recent_events)-- # Should have some events- assert len(events) > 0, 'Should have some recent events'- assert isinstance(events, list), 'Events should be a list'-- finally:- await browser_session.kill()