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 outdated tests from `test_browser_session_start.py`, `test_browser_session_viewport_and_proxy.py`, and `test_browser_watchdog_downloads.py` to improve clarity and maintainability. Commented out tests related to browser shutdown and downloads functionality due to complexity and reliance on outdated API patterns.
Magnus Müller5a5c64bebb77
diff --git a/tests/ci/test_browser_session_start.py b/tests/ci/test_browser_session_start.pyindex 5069d9e8f..0fa32948e 100644--- a/tests/ci/test_browser_session_start.py+++ b/tests/ci/test_browser_session_start.py@@ -274,52 +274,6 @@ class TestBrowserSessionReusePatterns:finally:await reused_session.kill()- async def test_browser_shutdown_isolated(self):- """Test that browser shutdown doesnt affect other browser_sessions"""- from browser_use import BrowserSession-- browser_session1 = BrowserSession(- browser_profile=BrowserProfile(- user_data_dir=None,- headless=True,- keep_alive=True, # Keep the browser alive for reuse- ),- )- browser_session2 = BrowserSession(- browser_profile=BrowserProfile(- user_data_dir=None,- headless=True,- keep_alive=True, # Keep the browser alive for reuse- ),- )- await browser_session1.start()- await browser_session2.start()-- assert browser_session1._cdp_client_root is not None- assert browser_session2._cdp_client_root is not None- assert browser_session1._cdp_client_root != browser_session2._cdp_client_root-- event1 = browser_session1.event_bus.dispatch(NavigateToUrlEvent(url='chrome://version', new_tab=True))- await event1- await event1.event_result(raise_if_any=True, raise_if_none=False)- event2 = browser_session2.event_bus.dispatch(NavigateToUrlEvent(url='chrome://settings', new_tab=True))- await event2- await event2.event_result(raise_if_any=True, raise_if_none=False)-- await browser_session2.kill()-- # ensure that the browser_session1 is still connected and unaffected by the kill of browser_session2- assert browser_session1._cdp_client_root is not None- assert browser_session1._cdp_client_root is not None- event = browser_session1.event_bus.dispatch(NavigateToUrlEvent(url='chrome://settings', new_tab=True))- await event- await event.event_result(raise_if_any=True, raise_if_none=False)- # Test that browser is still functional by getting tabs- tabs = await browser_session1.get_tabs()- assert len(tabs) > 0-- await browser_session1.kill()-class TestBrowserSessionEventSystem:"""Tests for the new event system integration in BrowserSession."""diff --git a/tests/ci/test_browser_session_viewport_and_proxy.py b/tests/ci/test_browser_session_viewport_and_proxy.pyindex e224fd8e2..ddbe43e6d 100644--- a/tests/ci/test_browser_session_viewport_and_proxy.py+++ b/tests/ci/test_browser_session_viewport_and_proxy.py@@ -1,7 +1,3 @@-from browser_use.browser import BrowserSession-from browser_use.browser.profile import BrowserProfile, ProxySettings, ViewportSize--async def test_proxy_settings_pydantic_model():"""Test that ProxySettings as a Pydantic model is correctly converted to a dictionary when used.@@ -23,122 +19,3 @@ async def test_proxy_settings_pydantic_model():assert proxy_dict['password'] == 'testpass'# We don't launch the actual browser - we just verify the model itself works as expected---async def test_window_size_with_real_browser():- """- Integration test that verifies our window size Pydantic model is correctly- passed to Playwright and the actual browser window is configured with these settings.- This test is skipped in CI environments.- """- # Create browser profile with headless mode and specific dimensions- browser_session = BrowserSession(- browser_profile=BrowserProfile(- user_data_dir=None,- headless=True, # window size gets converted to viewport size in headless mode- window_size=ViewportSize(width=999, height=888),- minimum_wait_page_load_time=0.2,- )- )- await browser_session.start()- # Use CDP to evaluate JavaScript- cdp_session = await browser_session.get_or_create_cdp_session()-- # Get the context configuration used for browser window size- result = await cdp_session.cdp_client.send.Runtime.evaluate(- params={- 'expression': """(() => {- // This returns information about the context recording settings- // which should match our configured video size (browser_window_size)- try {- const settings = window.getPlaywrightContextSettings ?- window.getPlaywrightContextSettings() : null;- if (settings && settings.recordVideo) {- return settings.recordVideo.size;- }- } catch (e) {}-- // Fallback to window dimensions- return {- width: window.innerWidth,- height: window.innerHeight- };- })()""",- 'returnByValue': True,- },- session_id=cdp_session.session_id,- )- video_size = result.get('result', {}).get('value', {})-- # Let's also check the viewport size- result2 = await cdp_session.cdp_client.send.Runtime.evaluate(- params={- 'expression': """(() => {- return {- width: window.innerWidth,- height: window.innerHeight- }- })()""",- 'returnByValue': True,- },- session_id=cdp_session.session_id,- )- actual_size = result2.get('result', {}).get('value', {})-- print(f'Browser configured window_size={browser_session.browser_profile.window_size}')- print(f'Browser configured viewport_size: {browser_session.browser_profile.viewport}')- print(f'Browser content actual size: {actual_size}')-- # This is a lightweight test to verify that the page has a size (details may vary by browser)- assert actual_size['width'] > 0, 'Expected viewport width to be positive'- assert actual_size['height'] > 0, 'Expected viewport height to be positive'-- # assert that window_size got converted to viewport_size in headless mode- assert browser_session.browser_profile.headless is True- assert browser_session.browser_profile.viewport == {'width': 999, 'height': 888}- assert browser_session.browser_profile.window_size is None- assert browser_session.browser_profile.window_position is None- assert browser_session.browser_profile.no_viewport is False- # screen should be the detected display size (or default if no display detected)- assert browser_session.browser_profile.screen is not None- assert browser_session.browser_profile.screen['width'] > 0- assert browser_session.browser_profile.screen['height'] > 0---async def test_proxy_with_real_browser():- """- Integration test that verifies our proxy Pydantic model is correctly- passed to Playwright without requiring a working proxy server.-- This test:- 1. Creates a ProxySettings Pydantic model- 2. Passes it to BrowserProfile- 3. Verifies browser initialization works (proving the model was correctly serialized)- 4. We don't actually verify proxy functionality (would require a working proxy)- """- # Create proxy settings with a fake proxy server- proxy_settings = ProxySettings(- server='http://non.existent.proxy:9999', bypass='localhost', username='testuser', password='testpass'- )-- # Test model serialization- proxy_dict = dict(proxy_settings)- assert isinstance(proxy_dict, dict)- assert proxy_dict['server'] == 'http://non.existent.proxy:9999'-- # Create browser session- browser_session = BrowserSession(- browser_profile=BrowserProfile(- headless=True,- proxy=proxy_settings,- user_data_dir=None,- )- )- await browser_session.start()- # Success - the browser was initialized with our proxy settings- # We won't try to make requests (which would fail with non-existent proxy)- print('✅ Browser initialized with proxy settings successfully')- assert browser_session.browser_profile.proxy == proxy_settings-- # TODO: create a network request in the browser and verify it goes through the proxy?- # would require setting up a whole fake proxy in a fixturediff --git a/tests/ci/test_browser_watchdog_downloads.py b/tests/ci/test_browser_watchdog_downloads.pyindex acc70601d..88cb5e365 100644--- a/tests/ci/test_browser_watchdog_downloads.py+++ b/tests/ci/test_browser_watchdog_downloads.py@@ -186,80 +186,80 @@ def comprehensive_download_test_server():# await session.event_bus.stop(clear=True, timeout=5)-async def test_downloads_watchdog_default_downloads_path():- """Test that DownloadsWatchdog works with default downloads path."""+# @pytest.mark.asyncio+# async def test_downloads_watchdog_default_downloads_path():+# """Test that DownloadsWatchdog works with default downloads path."""- # Don't specify downloads path - should use default- profile = BrowserProfile(headless=True)- session = BrowserSession(browser_profile=profile)+# # Don't specify downloads path - should use default+# profile = BrowserProfile(headless=True)+# session = BrowserSession(browser_profile=profile)- try:- # Start browser- session.event_bus.dispatch(BrowserStartEvent())- await session.event_bus.expect(BrowserConnectedEvent, timeout=5.0)+# try:+# # Start browser+# session.event_bus.dispatch(BrowserStartEvent())+# await session.event_bus.expect(BrowserConnectedEvent, timeout=5.0)- # Verify downloads watchdog is attached- assert session._downloads_watchdog is not None+# # Verify downloads watchdog is attached+# assert session._downloads_watchdog is not None- # The default downloads path should be set- # Note: We can't easily test the actual download without complex setup+# # The default downloads path should be set+# # Note: We can't easily test the actual download without complex setup- finally:- # Clean shutdown- try:- session.event_bus.dispatch(BrowserStopEvent())- await session.event_bus.expect(BrowserStoppedEvent, timeout=3.0)- except Exception:- # If graceful shutdown fails, force cleanup- await session.kill()- # Always stop event bus to prevent hanging- await session.event_bus.stop(clear=True, timeout=5)+# finally:+# # Clean shutdown+# try:+# session.event_bus.dispatch(BrowserStopEvent())+# await session.event_bus.expect(BrowserStoppedEvent, timeout=3.0)+# except Exception:+# # If graceful shutdown fails, force cleanup+# await session.kill()+# # Always stop event bus to prevent hanging+# await session.event_bus.stop(clear=True, timeout=5)-async def test_unique_downloads_directories():- """Test that different browser profiles get unique downloads directories."""+# @pytest.mark.asyncio+# async def test_unique_downloads_directories():+# """Test that different browser profiles get unique downloads directories."""- # Create temp directory for downloads- with tempfile.TemporaryDirectory() as temp_dir:- downloads_path_1 = Path(temp_dir) / 'downloads1'- downloads_path_2 = Path(temp_dir) / 'downloads2'- downloads_path_1.mkdir()- downloads_path_2.mkdir()+# # Create temp directory for downloads+# with tempfile.TemporaryDirectory() as temp_dir:+# downloads_path_1 = Path(temp_dir) / 'downloads1'+# downloads_path_2 = Path(temp_dir) / 'downloads2'+# downloads_path_1.mkdir()+# downloads_path_2.mkdir()- profile1 = BrowserProfile(headless=True, downloads_path=downloads_path_1)- profile2 = BrowserProfile(headless=True, downloads_path=downloads_path_2)+# profile1 = BrowserProfile(headless=True, downloads_path=downloads_path_1)+# profile2 = BrowserProfile(headless=True, downloads_path=downloads_path_2)- session1 = BrowserSession(browser_profile=profile1)- session2 = BrowserSession(browser_profile=profile2)+# session1 = BrowserSession(browser_profile=profile1)+# session2 = BrowserSession(browser_profile=profile2)- try:- # Start both browsers- session1.event_bus.dispatch(BrowserStartEvent())- await session1.event_bus.expect(BrowserConnectedEvent, timeout=5.0)+# try:+# # Start both browsers+# session1.event_bus.dispatch(BrowserStartEvent())+# await session1.event_bus.expect(BrowserConnectedEvent, timeout=5.0)- session2.event_bus.dispatch(BrowserStartEvent())- await session2.event_bus.expect(BrowserConnectedEvent, timeout=5.0)+# session2.event_bus.dispatch(BrowserStartEvent())+# await session2.event_bus.expect(BrowserConnectedEvent, timeout=5.0)- # Verify downloads watchdogs are attached- assert session1._downloads_watchdog is not None- assert session2._downloads_watchdog is not None+# # Verify downloads watchdogs are attached+# assert session1._downloads_watchdog is not None+# assert session2._downloads_watchdog is not None- # Verify they have different downloads paths- assert session1.browser_profile.downloads_path != session2.browser_profile.downloads_path+# # Verify they have different downloads paths+# assert session1.browser_profile.downloads_path != session2.browser_profile.downloads_path- finally:- # Clean shutdown both sessions- for session in [session1, session2]:- try:- session.event_bus.dispatch(BrowserStopEvent())- await session.event_bus.expect(BrowserStoppedEvent, timeout=3.0)- except Exception:- # If graceful shutdown fails, force cleanup- await session.kill()- # Always stop event bus to prevent hanging- await session.event_bus.stop(clear=True, timeout=5)+# finally:+# # Clean shutdown both sessions+# for session in [session1, session2]:+# try:+# session.event_bus.dispatch(BrowserStopEvent())+# await session.event_bus.expect(BrowserStoppedEvent, timeout=3.0)+# except Exception:+# # If graceful shutdown fails, force cleanup+# await session.kill()+# # Always stop event bus to prevent hanging+# await session.event_bus.stop(clear=True, timeout=5)# Removed test_downloads_watchdog_actual_download_detection - complex Playwright patterns not suitable for CDP