Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Delete files

Magnus Müllerdd6ec0bf0315
diff --git a/tests/ci/test_browser_session_tab_management.py b/tests/ci/test_browser_session_tab_management.py
deleted file mode 100644
index 92a7d3ce1..000000000
--- a/tests/ci/test_browser_session_tab_management.py
+++ /dev/null
@@ -1,294 +0,0 @@
-import asyncio
-import logging
-
-import pytest
-from dotenv import load_dotenv
-from pytest_httpserver import HTTPServer
-
-load_dotenv()
-
-from browser_use.browser.events import NavigateToUrlEvent
-from browser_use.browser.profile import BrowserProfile
-from browser_use.browser.session import BrowserSession
-from browser_use.tools.service import Tools
-
-# Set up test logging
-logger = logging.getLogger('tab_tests')
-# logger.setLevel(logging.DEBUG)
-
-
[email protected](scope='session')
-def http_server():
- """Create and provide a test HTTP server that serves static content."""
- server = HTTPServer()
- server.start()
-
- # Add routes for test pages
- server.expect_request('/page1').respond_with_data(
- '<html><head><title>Test Page 1</title></head><body><h1>Test Page 1</h1></body></html>', content_type='text/html'
- )
- server.expect_request('/page2').respond_with_data(
- '<html><head><title>Test Page 2</title></head><body><h1>Test Page 2</h1></body></html>', content_type='text/html'
- )
- server.expect_request('/page3').respond_with_data(
- '<html><head><title>Test Page 3</title></head><body><h1>Test Page 3</h1></body></html>', content_type='text/html'
- )
- server.expect_request('/page4').respond_with_data(
- '<html><head><title>Test Page 4</title></head><body><h1>Test Page 4</h1></body></html>', content_type='text/html'
- )
-
- yield server
- server.stop()
-
-
[email protected](scope='session')
-def base_url(http_server):
- """Return the base URL for the test HTTP server."""
- return f'http://{http_server.host}:{http_server.port}'
-
-
[email protected](scope='module')
-async def browser_session(base_url):
- """Create and provide a BrowserSession instance with a properly initialized tab."""
- browser_session = BrowserSession(
- browser_profile=BrowserProfile(
- user_data_dir=None,
- headless=True,
- keep_alive=True,
- )
- )
- await browser_session.start()
-
- # Create an initial tab using the navigate method which is more reliable
- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=f'{base_url}/page1', new_tab=True))
- await event
- await event.event_result(raise_if_any=True, raise_if_none=False)
-
- # Wait for navigation to complete
- await asyncio.sleep(1)
-
- # Verify that page is properly set
- current_url = await browser_session.get_current_page_url()
- assert base_url in current_url
-
- # page might be None initially until user interaction occurs
- # This is expected behavior with the new watchdog architecture
-
- yield browser_session
-
- await browser_session.kill()
-
- # Give playwright time to clean up
- await asyncio.sleep(0.1)
-
-
[email protected](scope='module')
-def tools():
- """Create and provide a Tools instance."""
- return Tools()
-
-
-class TestTabManagement:
- """Tests for the tab management system with separate page and page references."""
-
- # Helper methods
-
- async def _reset_tab_state(self, browser_session: BrowserSession, base_url: str):
- # await browser_session.event_bus.dispatch(CloseTabEvent(target_id=browser_session.agent_focus.target_id))
- # TODO: close all tabs using events + create new tab + focus it
- pass
-
- # Tab management tests
-
- # async def test_initial_values(self, browser_session, base_url):
- # """Test that open_tab correctly updates both tab references."""
-
- # await self._reset_tab_state(browser_session, base_url)
-
- # # Get current tab info using the new API
- # current_url = await browser_session.get_current_page_url()
- # assert current_url == 'about:blank'
- # # Note: browser_session.page property may not exist in new architecture
-
- # # Test that get_current_page works even after closing all tabs
- # for page in browser_session._cdp_client_root.pages:
- # await page.close()
-
- # # Give time for watchdogs to process tab closure events
- # await asyncio.sleep(0.5)
-
- # # should never be none even after all pages are closed - new system auto-creates
- # # Check that we can still get current URL (system should auto-create if needed)
- # current_url = await browser_session.get_current_page_url()
- # assert current_url is not None
- # assert current_url == 'about:blank'
- # run with pytest -k test_agent_changes_tab
- async def test_agent_changes_tab(self, browser_session: BrowserSession, base_url):
- """Test that page changes and page remains the same when a new tab is opened."""
-
- initial_tab = await self._reset_tab_state(browser_session, base_url)
- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=f'{base_url}/page1'))
- await event
- await event.event_result(raise_if_any=True, raise_if_none=False)
- current_url = await browser_session.get_current_page_url()
- assert current_url == f'{base_url}/page1'
- tabs = await browser_session.get_tabs()
- initial_tab_count = len(tabs)
-
- # Debug: Check tab count
- print(f'DEBUG: initial_tab_count = {initial_tab_count}')
- print(f'DEBUG: browser_session.tabs = {[p.url for p in tabs]}')
-
- # The test expects 1 tab, but if there's more we need to understand why
- if initial_tab_count != 1:
- print(f'WARNING: Expected 1 tab but found {initial_tab_count} tabs after _reset_tab_state')
- # For now, let's adjust the test to work with the actual count
- # TODO: fix this initial tab count issue
- pytest.skip('Initial tab count issue')
-
- # We expect at least 1 tab but there might be more due to event-driven architecture
- assert initial_tab_count >= 1
-
- # test opening a new tab
- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=f'{base_url}/page2', new_tab=True))
- await event
- await event.event_result(raise_if_any=True, raise_if_none=False)
- new_tabs = await browser_session.get_tabs()
- new_tab_count = len(new_tabs)
-
- # Debug: Check tab count after new tab creation
- print(f'DEBUG: new_tab_count = {new_tab_count}')
- print(f'DEBUG: browser_session.tabs count = {len(new_tabs)}')
- print(f'DEBUG: browser_session.tabs = {[p.url for p in new_tabs]}')
-
- # After creating a new tab, we should have one more tab than before
- expected_new_count = initial_tab_count + 1
- assert new_tab_count == expected_new_count
-
- # Give time for watchdogs to process the new tab creation
- await asyncio.sleep(1.0)
-
- # test agent open new tab updates agent focus
- current_url = await browser_session.get_current_page_url()
- assert current_url == f'{base_url}/page2'
-
- # test agent navigation updates agent focus
- event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=f'{base_url}/page3'))
- await event
- await event.event_result(raise_if_any=True, raise_if_none=False)
- current_url = await browser_session.get_current_page_url()
- assert current_url == f'{base_url}/page3' # agent should now be on the new tab
-
- # async def test_close_tab(self, browser_session, base_url):
- # """Test that closing a tab updates references correctly."""
-
- # initial_tab = await self._reset_tab_state(browser_session, base_url)
- # event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=f'{base_url}/page1'))
- # await event
- # await event.event_result(raise_if_any=True, raise_if_none=False)
- # # After navigation, current page should be the correct reference
- # current_url = await browser_session.get_current_page_url()
- # assert current_url == f'{base_url}/page1'
- # # The initial_tab (which was about:blank) should now show the new URL too
- # # (can't check old page object anymore, but current URL confirms navigation worked)
-
- # # Create two tabs with different URLs
- # event = browser_session.event_bus.dispatch(NavigateToUrlEvent(url=f'{base_url}/page2', new_tab=True))
- # await event
- # await event.event_result(raise_if_any=True, raise_if_none=False)
-
- # # Verify the second tab is now active
- # current_url = await browser_session.get_current_page_url()
- # assert current_url == f'{base_url}/page2'
-
- # # Close the second tab using CDP
- # tabs = await browser_session.get_tabs()
- # second_tab_id = None
- # for tab in tabs:
- # if f'{base_url}/page2' in tab.url:
- # second_tab_id = tab.target_id
- # break
-
- # if second_tab_id:
- # event = browser_session.event_bus.dispatch(CloseTabEvent(target_id=second_tab_id))
- # await event
- # await event.event_result(raise_if_any=True, raise_if_none=False)
- # await asyncio.sleep(0.5)
-
- # # Agent reference should be auto-updated to the first available tab
- # current_url = await browser_session.get_current_page_url()
- # assert current_url == f'{base_url}/page1'
- # # (can't check old page object anymore, but current URL confirms tab switch worked)
-
- # # close the only remaining tab using CDP
- # tabs = await browser_session.get_tabs()
- # if tabs:
- # first_tab_id = tabs[0].target_id
- # event = browser_session.event_bus.dispatch(CloseTabEvent(target_id=first_tab_id))
- # await event
- # await event.event_result(raise_if_any=True, raise_if_none=False)
- # await asyncio.sleep(0.5)
-
- # # close_tab should have called get_current_page, which creates a new about:blank tab if none are left
- # current_url = await browser_session.get_current_page_url()
- # assert current_url == 'about:blank'
-
-
-class TestEventDrivenTabOperations:
- """Tests for event-driven tab operations introduced in the session refactor."""
-
- @pytest.fixture(scope='function')
- async def browser_session(self):
- """Create a clean BrowserSession for event testing."""
- session = BrowserSession(browser_profile=BrowserProfile(headless=True, user_data_dir=None, keep_alive=False))
- await session.start()
- yield session
- await session.kill()
-
- # async def test_switch_tab_event_dispatching(self, browser_session, base_url):
- # """Test direct SwitchTabEvent dispatching."""
-
- # # Create multiple tabs
- # await browser_session.navigate_to(f'{base_url}/page1')
- # await browser_session.create_new_tab(f'{base_url}/page2')
- # await browser_session.create_new_tab(f'{base_url}/page3')
-
- # # Switch to tab 0 via direct event
- # switch_event = browser_session.event_bus.dispatch(SwitchTabEvent(target_id=browser_session.tabs[0].target_id))
- # await switch_event
-
- # # Verify the switch worked
- # current_url = await browser_session.get_current_page_url()
- # assert f'{base_url}/page1' in current_url
-
- # # Switch to tab 2 via direct event
- # switch_event = browser_session.event_bus.dispatch(SwitchTabEvent(target_id=browser_session.tabs[2].target_id))
- # await switch_event
-
- # # Verify the switch worked
- # current_url = await browser_session.get_current_page_url()
- # assert f'{base_url}/page3' in current_url
-
- # async def test_close_tab_event_dispatching(self, browser_session, base_url):
- # """Test direct CloseTabEvent dispatching."""
- # from browser_use.browser.events import TabClosedEvent
-
- # # Create multiple tabs
- # await browser_session.navigate_to(f'{base_url}/page1')
- # await browser_session.create_new_tab(f'{base_url}/page2')
-
- # initial_tab_count = len(browser_session.tabs)
- # assert initial_tab_count == 2
-
- # # Close tab 1 via direct event
- # close_event = browser_session.event_bus.dispatch(CloseTabEvent(target_id=browser_session.tabs[1].target_id))
- # await close_event
-
- # # Verify tab was closed
- # assert len(browser_session.tabs) == initial_tab_count - 1
-
- # # Check event history for TabClosedEvent
- # event_history = list(browser_session.event_bus.event_history.values())
- # closed_events = [e for e in event_history if isinstance(e, TabClosedEvent)]
- # assert len(closed_events) >= 1
- # assert closed_events[-1].target_id == browser_session.tabs[1].target_id
diff --git a/tests/ci/test_browser_session_via_cdp_tab_management.py b/tests/ci/test_browser_session_via_cdp_tab_management.py
deleted file mode 100644
index a0d099eac..000000000
--- a/tests/ci/test_browser_session_via_cdp_tab_management.py
+++ /dev/null
@@ -1,121 +0,0 @@
-"""Test CDP session handling when creating new tabs."""
-
-import asyncio
-
-import pytest
-
-from browser_use.browser.events import NavigateToUrlEvent, TabCreatedEvent
-from browser_use.browser.profile import BrowserProfile, ViewportSize
-from browser_use.browser.session import BrowserSession
-
-
-async def httpserver_url(httpserver):
- """Create a local HTTP server for testing."""
- httpserver.expect_request('/').respond_with_data(
- """
- <html>
- <head><title>Test Page</title></head>
- <body>
- <h1>Test Page</h1>
- <p>This is a test page</p>
- </body>
- </html>
- """,
- content_type='text/html',
- )
- return httpserver.url_for('/')
-
-
[email protected](reason='TODO: fix')
-async def test_new_tab_cdp_session_attachment(httpserver_url):
- """Test that CDP session is properly attached when creating new tabs."""
- browser = BrowserSession(browser_profile=BrowserProfile(headless=True, viewport=ViewportSize(width=800, height=600)))
-
- tab_created_events = []
-
- # Track TabCreatedEvent to verify it's dispatched correctly
- browser.event_bus.on(TabCreatedEvent, lambda event: tab_created_events.append(event))
-
- try:
- await browser.start()
-
- # Navigate to initial page
- nav_event = browser.event_bus.dispatch(NavigateToUrlEvent(url=httpserver_url))
- await nav_event
-
- # Clear any initial tab created events
- tab_created_events.clear()
-
- # Now create a new tab - this should trigger the CDP error if not fixed
- new_tab_event = browser.event_bus.dispatch(NavigateToUrlEvent(url=httpserver_url, new_tab=True))
- await new_tab_event
-
- # Wait a bit for all events to process
- await asyncio.sleep(1)
-
- # Verify that TabCreatedEvent was dispatched
- assert len(tab_created_events) == 1, f'Expected 1 TabCreatedEvent, got {len(tab_created_events)}'
- assert tab_created_events[0].url == httpserver_url
-
- # Verify we have 2 tabs now
- tabs = await browser.get_tabs()
- assert len(tabs) == 2, f'Expected 2 tabs, got {len(tabs)}'
-
- # Verify the CDP session is attached to the new tab
- assert browser.agent_focus is not None
- assert browser.agent_focus.target_id is not None
-
- # Try to execute a CDP command on the new tab to verify it works
- cdp_session = await browser.get_or_create_cdp_session()
- result = await cdp_session.cdp_client.send.Runtime.evaluate(
- params={'expression': 'document.title'}, session_id=cdp_session.session_id
- )
- assert result['result'].get('value') == 'Test Page'
-
- # Get browser state to verify DOM can be built on new tab
- from browser_use.browser.events import BrowserStateRequestEvent
-
- state_event = browser.event_bus.dispatch(BrowserStateRequestEvent())
- state = await state_event.event_result()
-
- # Verify state was retrieved without errors
- assert state is not None
- assert state.dom_state is not None
-
- finally:
- await browser.stop()
-
-
-async def test_multiple_new_tabs_cdp_session(httpserver_url):
- """Test creating multiple new tabs in succession."""
- browser = BrowserSession(browser_profile=BrowserProfile(headless=True, viewport=ViewportSize(width=800, height=600)))
-
- try:
- await browser.start()
-
- # Navigate to initial page
- nav_event = browser.event_bus.dispatch(NavigateToUrlEvent(url=httpserver_url))
- await nav_event
-
- # Create multiple new tabs quickly
- for i in range(3):
- new_tab_event = browser.event_bus.dispatch(NavigateToUrlEvent(url=f'{httpserver_url}?tab={i}', new_tab=True))
- await new_tab_event
-
- # Wait for events to process
- await asyncio.sleep(1)
-
- # Verify we have 4 tabs total (1 initial + 3 new)
- tabs = await browser.get_tabs()
- assert len(tabs) == 4, f'Expected 4 tabs, got {len(tabs)}'
-
- # Verify CDP commands work on the current tab
- cdp_session = await browser.get_or_create_cdp_session()
- result = await cdp_session.cdp_client.send.Runtime.evaluate(
- params={'expression': 'window.location.href'}, session_id=cdp_session.session_id
- )
- assert 'tab=2' in result['result'].get('value', ''), 'Should be on the last created tab'
-
- finally:
- await browser.stop()
diff --git a/tests/ci/test_browser_session_viewport_and_proxy.py b/tests/ci/test_browser_session_viewport_and_proxy.py
deleted file mode 100644
index ddbe43e6d..000000000
--- a/tests/ci/test_browser_session_viewport_and_proxy.py
+++ /dev/null
@@ -1,21 +0,0 @@
-async def test_proxy_settings_pydantic_model():
- """
- Test that ProxySettings as a Pydantic model is correctly converted to a dictionary when used.
- """
- # Create ProxySettings with Pydantic model
- proxy_settings = dict(server='http://example.proxy:8080', bypass='localhost', username='testuser', password='testpass')
-
- # Verify the model has correct dict-like access
- assert proxy_settings['server'] == 'http://example.proxy:8080'
- assert proxy_settings.get('bypass') == 'localhost'
- assert proxy_settings.get('nonexistent', 'default') == 'default'
-
- # Verify model_dump works correctly
- proxy_dict = dict(proxy_settings)
- assert isinstance(proxy_dict, dict)
- assert proxy_dict['server'] == 'http://example.proxy:8080'
- assert proxy_dict['bypass'] == 'localhost'
- assert proxy_dict['username'] == 'testuser'
- assert proxy_dict['password'] == 'testpass'
-
- # We don't launch the actual browser - we just verify the model itself works as expected
diff --git a/tests/ci/test_browser_watchdog_downloads.py b/tests/ci/test_browser_watchdog_downloads.py
deleted file mode 100644
index 88cb5e365..000000000
--- a/tests/ci/test_browser_watchdog_downloads.py
+++ /dev/null
@@ -1,265 +0,0 @@
-"""Test downloads watchdog functionality."""
-
-import asyncio
-import tempfile
-from pathlib import Path
-
-import pytest
-from pytest_httpserver import HTTPServer
-
-from browser_use.browser import BrowserSession
-from browser_use.browser.events import (
- BrowserConnectedEvent,
- BrowserStartEvent,
- BrowserStopEvent,
- BrowserStoppedEvent,
- NavigateToUrlEvent,
-)
-from browser_use.browser.profile import BrowserProfile
-
-
[email protected](reason='TODO: fix')
-async def test_downloads_watchdog_lifecycle():
- """Test that DownloadsWatchdog starts and stops with browser session."""
-
- # Create temp directory for downloads
- with tempfile.TemporaryDirectory() as temp_dir:
- downloads_path = Path(temp_dir)
-
- profile = BrowserProfile(headless=True, downloads_path=downloads_path)
- session = BrowserSession(browser_profile=profile)
-
- # Check that downloads watchdog is None initially
- assert session._downloads_watchdog is None
-
- try:
- # Start browser
- session.event_bus.dispatch(BrowserStartEvent())
- await session.event_bus.expect(BrowserConnectedEvent, timeout=5.0)
-
- # Check that downloads watchdog is attached
- assert session._downloads_watchdog is not None
-
- # Verify watchdog has proper session reference
- assert session._downloads_watchdog.browser_session is session
-
- 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)
-
-
[email protected](reason='TODO: fix')
-async def test_downloads_watchdog_file_detection(download_test_server):
- """Test that DownloadsWatchdog detects file downloads."""
-
- # Create temp directory for downloads
- with tempfile.TemporaryDirectory() as temp_dir:
- downloads_path = Path(temp_dir)
-
- profile = BrowserProfile(headless=True, downloads_path=downloads_path)
- session = BrowserSession(browser_profile=profile)
-
- try:
- # Start browser
- session.event_bus.dispatch(BrowserStartEvent())
- await session.event_bus.expect(BrowserConnectedEvent, timeout=5.0)
-
- # Navigate to test page
- test_url = download_test_server.url_for('/')
- await session.event_bus.dispatch(NavigateToUrlEvent(url=test_url))
-
- # Skip complex element selection for now - would need to implement selector-to-index conversion
- pytest.skip('Complex element selection needs refactoring for CDP events')
-
- # Wait for download to complete
- await asyncio.sleep(2.0)
-
- # Verify file was downloaded
- downloaded_files = list(downloads_path.glob('*'))
- assert len(downloaded_files) == 1, f'Expected 1 file, got {len(downloaded_files)}: {downloaded_files}'
-
- # Verify file content
- downloaded_file = downloaded_files[0]
- assert downloaded_file.name == 'test.pdf'
- assert downloaded_file.read_bytes() == b'PDF content'
-
- 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)
-
-
-def comprehensive_download_test_server():
- """Create a test server with downloadable files."""
- httpserver = HTTPServer(host='127.0.0.1', port=0)
- httpserver.start()
-
- # Serve a main page with download links
- main_page_html = """
- <!DOCTYPE html>
- <html>
- <head>
- <title>Download Test Page</title>
- </head>
- <body>
- <h1>Download Test Page</h1>
- <a href="/download/test.pdf" download="test.pdf">Download PDF</a>
- <br>
- <a href="/download/test.txt" download="test.txt">Download Text</a>
- </body>
- </html>
- """
-
- httpserver.expect_request('/').respond_with_data(main_page_html, content_type='text/html')
-
- # PDF handler
- httpserver.expect_request('/download/test.pdf').respond_with_data(
- b'PDF content', status=200, headers={'Content-Type': 'application/pdf'}
- )
-
- # Text handler
- httpserver.expect_request('/download/test.txt').respond_with_data(
- b'Text content', status=200, headers={'Content-Type': 'text/plain'}
- )
-
- yield httpserver
- httpserver.stop()
-
-
-# @pytest.mark.asyncio
-# async def test_downloads_watchdog_page_attachment():
-# """Test that DownloadsWatchdog attaches to pages properly."""
-
-# # Create temp directory for downloads
-# with tempfile.TemporaryDirectory() as temp_dir:
-# downloads_path = Path(temp_dir)
-
-# profile = BrowserProfile(headless=True, downloads_path=downloads_path)
-# session = BrowserSession(browser_profile=profile)
-
-# try:
-# # Start browser
-# session.event_bus.dispatch(BrowserStartEvent())
-# await session.event_bus.expect(BrowserConnectedEvent, timeout=5.0)
-
-# # Get downloads watchdog
-# downloads_watchdog = session._downloads_watchdog
-# assert downloads_watchdog is not None
-
-# # Navigate to create a new page
-# event = session.event_bus.dispatch(NavigateToUrlEvent(url='data:text/html,<h1>Test Page</h1>'))
-# await event
-# await event.event_result(raise_if_any=True, raise_if_none=False)
-
-# # Verify watchdog has pages with listeners
-# assert hasattr(downloads_watchdog, '_pages_with_listeners')
-
-# # Give it a moment for page attachment
-# await asyncio.sleep(0.2)
-
-# # The watchdog should have attached to at least one page
-# # Note: We can't easily verify the internal WeakSet without accessing private attrs
-
-# 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)
-
-
-# @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)
-
-# 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
-
-# # 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)
-
-
-# @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()
-
-# 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)
-
-# 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)
-
-# # 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
-
-# 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
diff --git a/tests/ci/test_browser_watchdog_downloads_simple.py b/tests/ci/test_browser_watchdog_downloads_simple.py
deleted file mode 100644
index c557a7740..000000000
--- a/tests/ci/test_browser_watchdog_downloads_simple.py
+++ /dev/null
@@ -1,33 +0,0 @@
-"""Test simple download functionality."""
-
-import pytest
-
-# Skip Playwright imports - removed dependency
-from pytest_httpserver import HTTPServer
-
-
-async def test_simple_playwright_download():
- """Test basic Playwright download functionality without browser-use - this just validates the browser setup"""
- # Skip Playwright usage - removed dependency
- pytest.skip('Playwright dependency removed')
-
-
[email protected](scope='function')
-def http_server():
- """Create a test HTTP server with a downloadable file."""
- server = HTTPServer()
- server.start()
-
- # Serve a simple text file for download
- server.expect_request('/download/test.txt').respond_with_data(
- 'Hello World from HTTP Server', status=200, headers={'Content-Type': 'text/plain'}
- )
-
- yield server
- server.stop()
-
-
-async def test_browser_use_download_with_http_server(http_server):
- """Test browser-use download with HTTP server and event coordination"""
- # Skip complex element selection for now - would need to implement selector-to-index conversion
- pytest.skip('Complex element selection needs refactoring for CDP events')
diff --git a/tests/ci/test_llm_gemini_type_field_fix.py b/tests/ci/test_llm_gemini_type_field_fix.py
deleted file mode 100644
index bca1ef716..000000000
--- a/tests/ci/test_llm_gemini_type_field_fix.py
+++ /dev/null
@@ -1,107 +0,0 @@
-"""
-Test to reproduce and verify fix for GitHub issue #2470:
-"Python field with name 'type' handled differently between Gemini and OpenAI GPT"
-"""
-
-from browser_use.llm.google.chat import ChatGoogle
-from browser_use.llm.schema import SchemaOptimizer
-
-
-class TestGeminiTypeFieldHandling:
- """Test class for reproducing the type field issue with Gemini schema processing."""
-
- def test_gemini_schema_with_dict_type_field(self):
- """
- Test that Gemini schema processing handles dict 'type' field gracefully.
- Reproduces the AttributeError: 'dict' object has no attribute 'upper'
- """
- chat_google = ChatGoogle(model='gemini-2.0-flash-exp')
-
- # Schema with dict instead of string in type field
- problematic_schema = {'type': {'malformed': 'dict_type'}, 'properties': {}}
-
- result = chat_google._fix_gemini_schema(problematic_schema)
- assert result is not None
- assert isinstance(result, dict)
- assert result['type'] == {'malformed': 'dict_type'}
-
- def test_gemini_schema_with_nested_dict_type_field(self):
- """
- Test that nested dict 'type' fields are handled gracefully.
- """
- chat_google = ChatGoogle(model='gemini-2.0-flash-exp')
-
- # Schema with nested dict type field
- problematic_schema = {
- 'type': 'object',
- 'properties': {'nested_field': {'type': {'malformed': 'dict_instead_of_string'}, 'properties': {}}},
- }
-
- result = chat_google._fix_gemini_schema(problematic_schema)
- assert result is not None
- assert isinstance(result, dict)
- nested_type = result['properties']['nested_field']['type']
- assert nested_type == {'malformed': 'dict_instead_of_string'}
-
- def test_gemini_schema_with_none_type_field(self):
- """Test handling of None type field."""
- chat_google = ChatGoogle(model='gemini-2.0-flash-exp')
-
- problematic_schema = {'type': 'object', 'properties': {'nested_field': {'type': None, 'properties': {}}}}
-
- result = chat_google._fix_gemini_schema(problematic_schema)
- assert result is not None
-
- def test_gemini_schema_with_valid_string_type(self):
- """Test that valid string type fields work correctly."""
- chat_google = ChatGoogle(model='gemini-2.0-flash-exp')
-
- valid_schema = {'type': 'object', 'properties': {'nested_field': {'type': 'object', 'properties': {}}}}
-
- # Should work without issues
- result = chat_google._fix_gemini_schema(valid_schema)
- assert result is not None
- assert isinstance(result, dict)
-
- def test_gemini_schema_with_empty_properties_object(self):
- """Test handling of empty properties in object type."""
- chat_google = ChatGoogle(model='gemini-2.0-flash-exp')
-
- schema_with_empty_props = {
- 'type': 'object',
- 'properties': {
- 'empty_object': {
- 'type': 'object',
- 'properties': {}, # Empty properties should get placeholder
- }
- },
- }
-
- result = chat_google._fix_gemini_schema(schema_with_empty_props)
-
- nested_props = result['properties']['empty_object']['properties']
- assert '_placeholder' in nested_props
- assert nested_props['_placeholder']['type'] == 'string'
-
- def test_consistency_between_providers(self):
- """
- Test that both Gemini and OpenAI handle schemas consistently.
- The original issue was that Gemini would fail where OpenAI succeeded.
- """
- from pydantic import BaseModel, Field
-
- # Create a test model that generates a schema with dict type
- class TestModel(BaseModel):
- field_with_dict_type: dict = Field(default_factory=dict)
-
- # OpenAI uses SchemaOptimizer directly
- openai_schema = SchemaOptimizer.create_optimized_json_schema(TestModel)
- assert openai_schema is not None
-
- # Gemini processes the schema through _fix_gemini_schema
- chat_google = ChatGoogle(model='gemini-2.0-flash-exp')
- gemini_result = chat_google._fix_gemini_schema(openai_schema)
- assert gemini_result is not None
-
- # Both should handle the schema without errors
- # This demonstrates that the fix makes Gemini consistent with OpenAI