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 old tests
Magnus Müller37746ecfa8b7
diff --git a/tests/old/httpx_client_test.py b/tests/old/httpx_client_test.pydeleted file mode 100644index dba431f3c..000000000--- a/tests/old/httpx_client_test.py+++ /dev/null@@ -1,38 +0,0 @@-import httpx--from browser_use.browser import BrowserProfile, BrowserSession---async def test_browser_close_doesnt_affect_external_httpx_clients():- """- Test that Browser.close() doesn't close HTTPX clients created outside the Browser instance.- This test demonstrates the issue where Browser.close() is closing all HTTPX clients.- """- # Create an external HTTPX client that should remain open- external_client = httpx.AsyncClient()-- # Create a BrowserSession instance- browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True))- await browser_session.start()-- # Close the browser (which should trigger cleanup_httpx_clients)- await browser_session.stop()-- # Check if the external client is still usable- try:- # If the client is closed, this will raise RuntimeError- # Using a simple HEAD request to a reliable URL- await external_client.head('https://www.example.com', timeout=2.0)- client_is_closed = False- except RuntimeError as e:- # If we get "Cannot send a request, as the client has been closed"- client_is_closed = 'client has been closed' in str(e)- except Exception:- # Any other exception means the client is not closed but request failed- client_is_closed = False- finally:- # Always clean up our test client properly- await external_client.aclose()-- # Our external client should not be closed by browser.close()- assert not client_is_closed, 'External HTTPX client was incorrectly closed by Browser.close()'diff --git a/tests/old/screenshot_test.py b/tests/old/screenshot_test.pydeleted file mode 100644index d4c357a6d..000000000--- a/tests/old/screenshot_test.py+++ /dev/null@@ -1,36 +0,0 @@-import asyncio-import base64--import pytest--from browser_use.browser import BrowserProfile, BrowserSession---async def test_take_full_page_screenshot():- browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True, disable_security=True))- await browser_session.start()- try:- page = await browser_session.get_current_page()- # Go to a test page- await page.goto('https://example.com')-- await asyncio.sleep(3)- # Take full page screenshot- screenshot_b64 = await browser_session.take_screenshot(full_page=True)- await asyncio.sleep(3)- # Verify screenshot is not empty and is valid base64- assert screenshot_b64 is not None- assert isinstance(screenshot_b64, str)- assert len(screenshot_b64) > 0-- # Test we can decode the base64 string- try:- base64.b64decode(screenshot_b64)- except Exception as e:- pytest.fail(f'Failed to decode base64 screenshot: {str(e)}')- finally:- await browser_session.stop()---if __name__ == '__main__':- asyncio.run(test_take_full_page_screenshot())diff --git a/tests/old/sync_live.py b/tests/old/sync_live.pydeleted file mode 100644index 6d39cc760..000000000--- a/tests/old/sync_live.py+++ /dev/null@@ -1,204 +0,0 @@-# """-# Live integration test for OAuth2 device flow with real cloud backend.--# This test is skipped by default and only runs when explicitly selected.-# Run with: pytest tests/ci/test_live_oauth2_integration.py::test_live_oauth2_integration -v-# """--# import asyncio-# import json-# import logging-# import os-# import tempfile-# from pathlib import Path--# import pytest--# from browser_use import Agent-# from browser_use.browser.browser import BrowserSession-# from browser_use.sync.service import CloudSync-# from tests.ci.conftest import create_mock_llm--# logger = logging.getLogger(__name__)---# def create_oauth_mock_llm():-# """Create a mock LLM that follows a simple script for OAuth testing."""-# actions = [-# # First action - navigate to a simple page-# json.dumps(-# {-# 'current_state': {-# 'evaluation_previous_goal': 'Starting OAuth integration test',-# 'memory': 'Beginning test sequence',-# 'next_goal': 'Navigate to example page',-# },-# 'action': [-# {'goto': {'url': 'https://example.com', 'reasoning': 'Starting the test by navigating to a simple webpage'}}-# ],-# }-# ),-# # Second action - complete the test-# json.dumps(-# {-# 'current_state': {-# 'evaluation_previous_goal': 'Successfully navigated to example page',-# 'memory': 'OAuth flow test initiated',-# 'next_goal': 'Complete test',-# },-# 'action': [{'done': {'text': 'OAuth integration test completed - cloud sync initiated', 'success': True}}],-# }-# ),-# ]-# return create_mock_llm(actions)---# @pytest.fixture-# def temp_browser_profile():-# """Create a temporary browser profile directory."""-# with tempfile.TemporaryDirectory() as tmpdir:-# profile_dir = Path(tmpdir) / 'browser_profile'-# profile_dir.mkdir(parents=True, exist_ok=True)-# yield str(profile_dir)---# @pytest.mark.skipif(not os.getenv('RUN_LIVE_TESTS'), reason='Live integration tests only run when RUN_LIVE_TESTS=1 is set')-# @pytest.mark.asyncio-# async def test_live_oauth2_integration(temp_browser_profile):-# """-# Live integration test for OAuth2 device flow.--# This test:-# 1. Creates a real browser session-# 2. Sets up cloud sync with real backend-# 3. Runs an agent with a mocked LLM-# 4. Verifies the OAuth2 device flow is initiated-# 5. Sends real events to the cloud backend--# Environment variables required:-# - RUN_LIVE_TESTS=1 (to enable the test)-# - BROWSER_USE_CLOUD_API_URL (optional, defaults to https://cloud.browser-use.com)-# """--# # Configuration-# backend_url = os.getenv('BROWSER_USE_CLOUD_API_URL', 'http://localhost:8000')-# logger.info(f'Running live integration test against: {backend_url}')--# # Create mock LLM-# mock_llm = create_oauth_mock_llm()--# # Set environment variables for cloud sync-# os.environ['BROWSERUSE_CLOUD_SYNC'] = 'true'-# os.environ['BROWSER_USE_CLOUD_API_URL'] = backend_url--# # Create browser session with real profile-# browser_session = BrowserSession(-# user_data_dir=temp_browser_profile,-# headless=False, # Show browser for visual confirmation-# )--# # Create agent (cloud sync will be auto-enabled via environment variables)-# agent = Agent(-# task='Visit the Browser Use login page and demonstrate OAuth integration',-# llm=mock_llm,-# browser_session=browser_session,-# )--# # Run the agent for a short time-# logger.info('Starting agent with OAuth2 integration...')--# # Run with timeout to prevent hanging-# try:-# await asyncio.wait_for(agent.run(), timeout=60)-# except TimeoutError:-# logger.info('Agent run timed out (expected for live test)')--# # Get cloud sync from agent-# cloud_sync = agent.cloud_sync-# assert cloud_sync is not None, 'Cloud sync should be enabled'--# # Wait for any pending cloud sync operations-# if cloud_sync.auth_task and not cloud_sync.auth_task.done():-# try:-# await asyncio.wait_for(cloud_sync.auth_task, timeout=10)-# except TimeoutError:-# logger.info('Auth task still running (expected for live test)')--# # Verify cloud sync was attempted-# assert cloud_sync.auth_client is not None, 'Auth client should be initialized'--# logger.info('✅ Live OAuth2 integration test completed successfully')-# logger.info(f'🔗 LLM invocations: {mock_llm.invoke.call_count if hasattr(mock_llm.invoke, "call_count") else "mock"}')--# # Print session ID for manual verification-# if cloud_sync.session_id:-# logger.info(f'📊 Agent session ID: {cloud_sync.session_id}')-# logger.info(f'🌐 Check session at: {backend_url}/agent/{cloud_sync.session_id}')--# await asyncio.sleep(60000)---# @pytest.mark.skipif(not os.getenv('RUN_LIVE_TESTS'), reason='Live integration tests only run when RUN_LIVE_TESTS=1 is set')-# @pytest.mark.asyncio-# async def test_live_cloud_sync_events():-# """-# Test that cloud sync can send events to the real backend.--# This is a simpler test that just verifies event sending works.-# """--# backend_url = os.getenv('BROWSER_USE_CLOUD_API_URL', 'http://localhost:8000')-# logger.info(f'Testing cloud sync against: {backend_url}')--# # Create cloud sync service-# cloud_sync = CloudSync(base_url=backend_url, enable_auth=True)--# # Import event types-# from uuid import uuid4--# from browser_use.agent.cloud_events import CreateAgentSessionEvent-# from browser_use.sync.auth import TEMP_USER_ID--# # Create a test session event-# session_event = CreateAgentSessionEvent(-# user_id=TEMP_USER_ID,-# id=str(uuid4()),-# browser_session_id=str(uuid4()),-# browser_session_live_url='https://example.com',-# browser_session_cdp_url='ws://localhost:9222',-# browser_state={'test': 'live_integration'},-# is_source_api=True,-# )--# # Send event to cloud-# logger.info('Sending test event to cloud...')-# try:-# await cloud_sync.handle_event(session_event)-# logger.info('✅ Event sent successfully')-# except Exception as e:-# logger.error(f'❌ Failed to send event: {e}')-# raise--# # Wait a moment for processing-# await asyncio.sleep(2)--# logger.info('✅ Cloud sync event test completed')--# if cloud_sync.session_id:-# logger.info(f'📊 Session ID: {cloud_sync.session_id}')--# await asyncio.sleep(60000)---# if __name__ == '__main__':-# # Allow running the test directly with: python test_live_oauth2_integration.py-# import sys--# if len(sys.argv) > 1 and sys.argv[1] == '--live':-# os.environ['RUN_LIVE_TESTS'] = '1'-# pytest.main([__file__, '-v', '-s'])-# else:-# print('To run live integration tests:')-# print('1. Set environment variable: export RUN_LIVE_TESTS=1')-# print('2. Run: pytest tests/ci/test_live_oauth2_integration.py -v')-# print('3. Or run directly: python test_live_oauth2_integration.py --live')diff --git a/tests/old/test_action_filters.py b/tests/old/test_action_filters.pydeleted file mode 100644index 8e5d2f9ab..000000000--- a/tests/old/test_action_filters.py+++ /dev/null@@ -1,305 +0,0 @@-from unittest.mock import MagicMock--import pytest-from pydantic import BaseModel--from browser_use.browser.types import Page-from browser_use.tools.registry.service import Registry-from browser_use.tools.registry.views import ActionRegistry, RegisteredAction---class EmptyParamModel(BaseModel):- pass---class TestActionFilters:- def test_get_prompt_description_no_filters(self):- """Test that system prompt only includes actions with no filters"""- registry = ActionRegistry()-- # Add actions with and without filters- no_filter_action = RegisteredAction(- name='no_filter_action',- description='Action with no filters',- function=lambda: None,- param_model=EmptyParamModel,- domains=None,- page_filter=None,- )-- page_filter_action = RegisteredAction(- name='page_filter_action',- description='Action with page filter',- function=lambda: None,- param_model=EmptyParamModel,- domains=None,- page_filter=lambda page: True,- )-- domain_filter_action = RegisteredAction(- name='domain_filter_action',- description='Action with domain filter',- function=lambda: None,- param_model=EmptyParamModel,- domains=['example.com'],- page_filter=None,- )-- registry.actions = {- 'no_filter_action': no_filter_action,- 'page_filter_action': page_filter_action,- 'domain_filter_action': domain_filter_action,- }-- # System prompt (no page) should only include actions with no filters- system_description = registry.get_prompt_description()- assert 'no_filter_action' in system_description- assert 'page_filter_action' not in system_description- assert 'domain_filter_action' not in system_description-- def test_page_filter_matching(self):- """Test that page filters work correctly"""- registry = ActionRegistry()-- # Create a mock page- mock_page = MagicMock(spec=Page)- mock_page.url = 'https://example.com/page'-- # Create actions with different page filters- matching_action = RegisteredAction(- name='matching_action',- description='Action with matching page filter',- function=lambda: None,- param_model=EmptyParamModel,- domains=None,- page_filter=lambda page: 'example.com' in page.url,- )-- non_matching_action = RegisteredAction(- name='non_matching_action',- description='Action with non-matching page filter',- function=lambda: None,- param_model=EmptyParamModel,- domains=None,- page_filter=lambda page: 'other.com' in page.url,- )-- registry.actions = {'matching_action': matching_action, 'non_matching_action': non_matching_action}-- # Page-specific description should only include matching actions- page_description = registry.get_prompt_description(mock_page)- assert 'matching_action' in page_description- assert 'non_matching_action' not in page_description-- def test_domain_filter_matching(self):- """Test that domain filters work correctly with glob patterns"""- registry = ActionRegistry()-- # Create actions with different domain patterns- actions = {- 'exact_match': RegisteredAction(- name='exact_match',- description='Exact domain match',- function=lambda: None,- param_model=EmptyParamModel,- domains=['example.com'],- page_filter=None,- ),- 'subdomain_match': RegisteredAction(- name='subdomain_match',- description='Subdomain wildcard match',- function=lambda: None,- param_model=EmptyParamModel,- domains=['*.example.com'],- page_filter=None,- ),- 'prefix_match': RegisteredAction(- name='prefix_match',- description='Prefix wildcard match',- function=lambda: None,- param_model=EmptyParamModel,- domains=['example*'],- page_filter=None,- ),- 'non_matching': RegisteredAction(- name='non_matching',- description='Non-matching domain',- function=lambda: None,- param_model=EmptyParamModel,- domains=['other.com'],- page_filter=None,- ),- }-- registry.actions = actions-- # Test exact domain match- mock_page = MagicMock(spec=Page)- mock_page.url = 'https://example.com/page'-- exact_match_description = registry.get_prompt_description(mock_page)- assert 'exact_match' in exact_match_description- assert 'non_matching' not in exact_match_description-- # Test subdomain match- mock_page.url = 'https://sub.example.com/page'- subdomain_match_description = registry.get_prompt_description(mock_page)- assert 'subdomain_match' in subdomain_match_description- assert 'exact_match' not in subdomain_match_description-- # Test prefix match- mock_page.url = 'https://example123.org/page'- prefix_match_description = registry.get_prompt_description(mock_page)- assert 'prefix_match' in prefix_match_description-- def test_domain_and_page_filter_together(self):- """Test that actions can be filtered by both domain and page filter"""- registry = ActionRegistry()-- # Create a mock page- mock_page = MagicMock(spec=Page)- mock_page.url = 'https://example.com/admin'-- # Actions with different combinations of filters- actions = {- 'domain_only': RegisteredAction(- name='domain_only',- description='Domain filter only',- function=lambda: None,- param_model=EmptyParamModel,- domains=['example.com'],- page_filter=None,- ),- 'page_only': RegisteredAction(- name='page_only',- description='Page filter only',- function=lambda: None,- param_model=EmptyParamModel,- domains=None,- page_filter=lambda page: 'admin' in page.url,- ),- 'both_matching': RegisteredAction(- name='both_matching',- description='Both filters matching',- function=lambda: None,- param_model=EmptyParamModel,- domains=['example.com'],- page_filter=lambda page: 'admin' in page.url,- ),- 'both_one_fail': RegisteredAction(- name='both_one_fail',- description='One filter fails',- function=lambda: None,- param_model=EmptyParamModel,- domains=['other.com'],- page_filter=lambda page: 'admin' in page.url,- ),- }-- registry.actions = actions-- # Check that only actions with matching filters are included- description = registry.get_prompt_description(mock_page)- assert 'domain_only' in description # Domain matches- assert 'page_only' in description # Page filter matches- assert 'both_matching' in description # Both filters match- assert 'both_one_fail' not in description # Domain filter fails-- # Test with different URL where page filter fails- mock_page.url = 'https://example.com/dashboard'- description = registry.get_prompt_description(mock_page)- assert 'domain_only' in description # Domain matches- assert 'page_only' not in description # Page filter fails- assert 'both_matching' not in description # Page filter fails- assert 'both_one_fail' not in description # Domain filter fails-- @pytest.mark.asyncio- async def test_registry_action_decorator(self):- """Test the action decorator with filters"""- registry = Registry()-- # Define actions with different filters- @registry.action(- description='No filter action',- )- def no_filter_action():- pass-- @registry.action(description='Domain filter action', domains=['example.com'])- def domain_filter_action():- pass-- @registry.action(description='Page filter action', page_filter=lambda page: 'admin' in page.url)- def page_filter_action():- pass-- # Check that system prompt only includes the no_filter_action- system_description = registry.get_prompt_description()- assert 'No filter action' in system_description- assert 'Domain filter action' not in system_description- assert 'Page filter action' not in system_description-- # Check that page-specific prompt includes the right actions- mock_page = MagicMock(spec=Page)- mock_page.url = 'https://example.com/admin'-- page_description = registry.get_prompt_description(mock_page)- assert 'Domain filter action' in page_description- assert 'Page filter action' in page_description-- @pytest.mark.asyncio- async def test_action_model_creation(self):- """Test that action models are created correctly with filters"""- registry = Registry()-- # Define actions with different filters- @registry.action(- description='No filter action',- )- def no_filter_action():- pass-- @registry.action(description='Domain filter action', domains=['example.com'])- def domain_filter_action():- pass-- @registry.action(description='Page filter action', page_filter=lambda page: 'admin' in page.url)- def page_filter_action():- pass-- @registry.action(description='Both filters action', domains=['example.com'], page_filter=lambda page: 'admin' in page.url)- def both_filters_action():- pass-- # Initial action model should only include no_filter_action- initial_model = registry.create_action_model()- assert 'no_filter_action' in initial_model.model_fields- assert 'domain_filter_action' not in initial_model.model_fields- assert 'page_filter_action' not in initial_model.model_fields- assert 'both_filters_action' not in initial_model.model_fields-- # Action model with matching page should include all matching actions- mock_page = MagicMock(spec=Page)- mock_page.url = 'https://example.com/admin'-- page_model = registry.create_action_model(page=mock_page)- assert 'no_filter_action' in page_model.model_fields- assert 'domain_filter_action' in page_model.model_fields- assert 'page_filter_action' in page_model.model_fields- assert 'both_filters_action' in page_model.model_fields-- # Action model with non-matching domain should exclude domain-filtered actions- mock_page.url = 'https://other.com/admin'- non_matching_domain_model = registry.create_action_model(page=mock_page)- assert 'no_filter_action' in non_matching_domain_model.model_fields- assert 'domain_filter_action' not in non_matching_domain_model.model_fields- assert 'page_filter_action' in non_matching_domain_model.model_fields- assert 'both_filters_action' not in non_matching_domain_model.model_fields-- # Action model with non-matching page filter should exclude page-filtered actions- mock_page.url = 'https://example.com/dashboard'- non_matching_page_model = registry.create_action_model(page=mock_page)- assert 'no_filter_action' in non_matching_page_model.model_fields- assert 'domain_filter_action' in non_matching_page_model.model_fields- assert 'page_filter_action' not in non_matching_page_model.model_fields- assert 'both_filters_action' not in non_matching_page_model.model_fieldsdiff --git a/tests/old/test_agent_actions.py b/tests/old/test_agent_actions.pydeleted file mode 100644index 0e6b0b513..000000000--- a/tests/old/test_agent_actions.py+++ /dev/null@@ -1,192 +0,0 @@-import pytest-from pydantic import BaseModel--from browser_use.agent.service import Agent-from browser_use.agent.views import AgentHistoryList-from browser_use.browser import BrowserSession-from browser_use.llm import ChatAzureOpenAI---def llm():- """Initialize language model for testing"""-- # return ChatAnthropic(model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None)- return ChatAzureOpenAI(model='gpt-4.1')- # return ChatOpenAI(model='gpt-4.1-mini')--[email protected](scope='module')-async def browser_session():- from browser_use.browser.profile import BrowserProfile-- profile = BrowserProfile(headless=True, user_data_dir=None)- browser_session = BrowserSession(browser_profile=profile)- await browser_session.start()- yield browser_session- await browser_session.kill()---# pytest tests/test_agent_actions.py -v -k "test_ecommerce_interaction" --capture=no-# @pytest.mark.asyncio[email protected](reason='Kinda expensive to run')-async def test_ecommerce_interaction(llm, browser_session):- """Test complex ecommerce interaction sequence"""- agent = Agent(- task="Go to amazon.com, search for 'laptop', filter by 4+ stars, and find the price of the first result",- llm=llm,- browser_session=browser_session,- save_conversation_path='tmp/test_ecommerce_interaction/conversation',- )-- history: AgentHistoryList = await agent.run(max_steps=20)-- # Verify sequence of actions- action_sequence = []- for action in history.model_actions():- action_name = list(action.keys())[0]- if action_name in ['go_to_url']:- action_sequence.append('navigate')- elif action_name == 'input_text':- action_sequence.append('input')- # Check that the input is 'laptop'- inp = action['input_text']['text'].lower() # type: ignore- if inp == 'laptop':- action_sequence.append('input_exact_correct')- elif 'laptop' in inp:- action_sequence.append('correct_in_input')- else:- action_sequence.append('incorrect_input')- elif action_name == 'click_element':- action_sequence.append('click')-- # Verify essential steps were performed- assert 'navigate' in action_sequence # Navigated to Amazon- assert 'input' in action_sequence # Entered search term- assert 'click' in action_sequence # Clicked search/filter- assert 'input_exact_correct' in action_sequence or 'correct_in_input' in action_sequence---async def test_error_recovery(llm, browser_session):- """Test agent's ability to recover from errors"""- agent = Agent(- task='Navigate to nonexistent-site.com and then recover by going to google.com ',- llm=llm,- browser_session=browser_session,- )-- history: AgentHistoryList = await agent.run(max_steps=10)-- actions_names = history.action_names()- actions = history.model_actions()- assert 'go_to_url' in actions_names, f'{actions_names} does not contain go_to_url'- for action in actions:- if 'go_to_url' in action:- assert 'url' in action['go_to_url'], 'url is not in go_to_url'- assert action['go_to_url']['url'].endswith('google.com'), 'url does not end with google.com'- break---async def test_find_contact_email(llm, browser_session):- """Test agent's ability to find contact email on a website"""- agent = Agent(- task='Go to https://browser-use.com/ and find out the contact email',- llm=llm,- browser_session=browser_session,- )-- history: AgentHistoryList = await agent.run(max_steps=10)-- # Verify the agent found the contact email- extracted_content = history.extracted_content()- email = '[email protected]'- for content in extracted_content:- if email in content:- break- else:- pytest.fail(f'{extracted_content} does not contain {email}')---async def test_agent_finds_installation_command(llm, browser_session):- """Test agent's ability to find the pip installation command for browser-use on the web"""- agent = Agent(- task='Find the pip installation command for the browser-use repo',- llm=llm,- browser_session=browser_session,- )-- history: AgentHistoryList = await agent.run(max_steps=10)-- # Verify the agent found the correct installation command- extracted_content = history.extracted_content()- install_command = 'pip install browser-use'- for content in extracted_content:- if install_command in content:- break- else:- pytest.fail(f'{extracted_content} does not contain {install_command}')---class CaptchaTest(BaseModel):- name: str- url: str- success_text: str- additional_text: str | None = None---# run 3 test: python -m pytest tests/test_agent_actions.py -v -k "test_captcha_solver" --capture=no --log-cli-level=INFO-# pytest tests/test_agent_actions.py -v -k "test_captcha_solver" --capture=no --log-cli-level=INFO- 'captcha',- [- CaptchaTest(- name='Text Captcha',- url='https://2captcha.com/demo/text',- success_text='Captcha is passed successfully!',- ),- CaptchaTest(- name='Basic Captcha',- url='https://captcha.com/demos/features/captcha-demo.aspx',- success_text='Correct!',- ),- CaptchaTest(- name='Rotate Captcha',- url='https://2captcha.com/demo/rotatecaptcha',- success_text='Captcha is passed successfully',- additional_text='Use multiple clicks at once. click done when image is exact correct position.',- ),- CaptchaTest(- name='MT Captcha',- url='https://2captcha.com/demo/mtcaptcha',- success_text='Verified Successfully',- additional_text='Stop when you solved it successfully.',- ),- ],-)-async def test_captcha_solver(llm, browser_session, captcha: CaptchaTest):- """Test agent's ability to solve different types of captchas"""- agent = Agent(- task=f'Go to {captcha.url} and solve the captcha. {captcha.additional_text}',- llm=llm,- browser_session=browser_session,- )- from browser_use.agent.views import AgentHistoryList-- history: AgentHistoryList = await agent.run(max_steps=7)-- # Get page content to verify success- page = await browser_session.get_current_page()- all_text = await page.content()-- if not all_text:- all_text = ''-- if not isinstance(all_text, str):- all_text = str(all_text)-- solved = captcha.success_text in all_text- assert solved, f'Failed to solve {captcha.name}'-- # python -m pytest tests/test_agent_actions.py -v --capture=no-- # pytest tests/test_agent_actions.py -v -k "test_captcha_solver" --capture=no --log-cli-level=INFOdiff --git a/tests/old/test_clicks.py b/tests/old/test_clicks.pydeleted file mode 100644index 4908cf0ab..000000000--- a/tests/old/test_clicks.py+++ /dev/null@@ -1,98 +0,0 @@-import asyncio-import json--import anyio--from browser_use.browser import BrowserProfile, BrowserSession-from browser_use.browser.events import ClickElementEvent-from browser_use.dom.views import DOMBaseNode, DOMElementNode, DOMTextNode-from browser_use.utils import time_execution_sync---class ElementTreeSerializer:- @staticmethod- def dom_element_node_to_json(element_tree: DOMElementNode) -> dict:- def node_to_dict(node: DOMBaseNode) -> dict:- if isinstance(node, DOMTextNode):- return {'type': 'text', 'text': node.text}- elif isinstance(node, DOMElementNode):- return {- 'type': 'element',- 'tag_name': node.tag_name,- 'attributes': node.attributes,- 'highlight_index': node.highlight_index,- 'children': [node_to_dict(child) for child in node.children],- }- return {}-- return node_to_dict(element_tree)---# run with: pytest browser_use/browser/tests/test_clicks.py-async def test_highlight_elements():- browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True))- await browser_session.start()- try:- page = await browser_session.get_current_page()- # await page.goto('https://immobilienscout24.de')- # await page.goto('https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/service-plans')- # await page.goto('https://google.com/search?q=elon+musk')- # await page.goto('https://kayak.com')- # await page.goto('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe')- # await page.goto('https://dictionary.cambridge.org')- # await page.goto('https://github.com')- await page.goto('https://huggingface.co/')-- await asyncio.sleep(1)-- while True:- try:- # await asyncio.sleep(10)- state = await browser_session.get_state_summary(cache_clickable_elements_hashes=True)-- async with await anyio.open_file('./tmp/page.json', 'w') as f:- await f.write(- json.dumps(- ElementTreeSerializer.dom_element_node_to_json(state.element_tree),- indent=1,- )- )-- # await time_execution_sync('highlight_selector_map_elements')(- # browser.highlight_selector_map_elements- # )(state.selector_map)-- # Find and print duplicate XPaths- xpath_counts = {}- if not state.dom_state.selector_map:- continue- for selector in state.dom_state.selector_map.values():- xpath = selector.xpath- if xpath in xpath_counts:- xpath_counts[xpath] += 1- else:- xpath_counts[xpath] = 1-- print('\nDuplicate XPaths found:')- for xpath, count in xpath_counts.items():- if count > 1:- print(f'XPath: {xpath}')- print(f'Count: {count}\n')-- print(list(state.selector_map.keys()), 'Selector map keys')- print(state.element_tree.clickable_elements_to_string())- action = input('Select next action: ')-- await time_execution_sync('remove_highlight_elements')(browser_session.remove_highlights)()-- node_element = state.dom_state.selector_map[int(action)]-- # check if index of selector map are the same as index of items in dom_items-- event = browser_session.event_bus.dispatch(ClickElementEvent(element_node=node_element))- await event-- except Exception as e:- print(e)- finally:- await browser_session.stop()diff --git a/tests/old/test_core_functionality.py b/tests/old/test_core_functionality.pydeleted file mode 100644index 8da0a134c..000000000--- a/tests/old/test_core_functionality.py+++ /dev/null@@ -1,284 +0,0 @@-import pytest-from pytest_httpserver import HTTPServer--from browser_use import setup_logging-from browser_use.llm import ChatOpenAI--setup_logging()--from browser_use.agent.service import Agent-from browser_use.agent.views import AgentHistoryList-from browser_use.browser import BrowserSession---class TestCoreFunctionality:- """Tests for core functionality of the Agent using real browser instances."""-- @pytest.fixture(scope='session')- def http_server(self):- """Create and provide a test HTTP server that serves static content."""- server = HTTPServer()- server.start()-- # Add routes for common test pages- server.expect_request('/').respond_with_data(- '<html><head><title>Test Home Page</title></head><body><h1>Test Home Page</h1><p>Welcome to the test site</p></body></html>',- content_type='text/html',- )-- server.expect_request('/page1').respond_with_data(- '<html><head><title>Test Page 1</title></head><body><h1>Test Page 1</h1><p>This is test page 1</p><a href="/page2">Link to Page 2</a></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><p>This is test page 2</p><a href="/page1">Back to Page 1</a></body></html>',- content_type='text/html',- )-- server.expect_request('/search').respond_with_data(- """- <html>- <head><title>Search Results</title></head>- <body>- <h1>Search Results</h1>- <form>- <input type="text" id="search-box" placeholder="Search...">- <button type="submit">Search</button>- </form>- <div class="results">- <div class="result">Result 1</div>- <div class="result">Result 2</div>- <div class="result">Result 3</div>- </div>- </body>- </html>- """,- content_type='text/html',- )-- yield server- server.stop()-- @pytest.fixture(scope='session')- def base_url(self, http_server):- """Return the base URL for the test HTTP server."""- return f'http://{http_server.host}:{http_server.port}'-- @pytest.fixture(scope='module')- async def browser_session(self):- """Create and provide a BrowserSession instance with security disabled."""- from browser_use.browser.profile import BrowserProfile-- profile = BrowserProfile(headless=True, user_data_dir=None)- browser_session = BrowserSession(browser_profile=profile)- yield browser_session- await browser_session.kill()-- @pytest.fixture(scope='module')- def llm(self):- """Initialize language model for testing with minimal settings."""- return ChatOpenAI(- model='gpt-4.1',- temperature=0.0,- )-- async def test_search_google(self, llm, browser_session, base_url):- """Test 'Search Google' action using a mock search page."""- agent = Agent(- task=f"Go to '{base_url}/search' and search for 'OpenAI'.",- llm=llm,- browser_session=browser_session,- )- history: AgentHistoryList = await agent.run(max_steps=3)- action_names = history.action_names()- assert 'go_to_url' in action_names- assert any('input_text' in action or 'click_element_by_index' in action for action in action_names)-- async def test_go_to_url(self, llm, browser_session, base_url):- """Test 'Navigate to URL' action."""- agent = Agent(- task=f"Navigate to '{base_url}/page1'.",- llm=llm,- browser_session=browser_session,- )- history = await agent.run(max_steps=2)- action_names = history.action_names()- assert 'go_to_url' in action_names-- # Verify we're on the correct page- page = await browser_session.get_current_page()- assert f'{base_url}/page1' in page.url-- async def test_go_back(self, llm, browser_session, base_url):- """Test 'Go back' action."""- # First navigate to page1, then to page2, then go back- agent = Agent(- task=f"Go to '{base_url}/page1', then go to '{base_url}/page2', then go back.",- llm=llm,- browser_session=browser_session,- )- history = await agent.run(max_steps=4)- action_names = history.action_names()- assert 'go_to_url' in action_names- assert 'go_back' in action_names-- # Verify we're back on page1- page = await browser_session.get_current_page()- assert f'{base_url}/page1' in page.url-- async def test_click_element(self, llm, browser_session, base_url):- """Test 'Click element' action."""- agent = Agent(- task=f"Go to '{base_url}/page1' and click on the link to Page 2.",- llm=llm,- browser_session=browser_session,- )- history = await agent.run(max_steps=3)- action_names = history.action_names()- assert 'go_to_url' in action_names- assert 'click_element_by_index' in action_names-- # Verify we're now on page2 after clicking the link- page = await browser_session.get_current_page()- assert f'{base_url}/page2' in page.url-- async def test_input_text(self, llm, browser_session, base_url):- """Test 'Input text' action."""- agent = Agent(- task=f"Go to '{base_url}/search' and input 'OpenAI' into the search box.",- llm=llm,- browser_session=browser_session,- )- history = await agent.run(max_steps=3)- action_names = history.action_names()- assert 'go_to_url' in action_names- assert 'input_text' in action_names-- # Verify text was entered in the search box- page = await browser_session.get_current_page()- search_value = await page.evaluate("document.getElementById('search-box').value")- assert 'OpenAI' in search_value-- async def test_switch_tab(self, llm, browser_session, base_url):- """Test 'Switch tab' action."""- agent = Agent(- task=f"Open '{base_url}/page1' in the current tab, then open a new tab with '{base_url}/page2', then switch back to the first tab.",- llm=llm,- browser_session=browser_session,- )- history = await agent.run(max_steps=4)- action_names = history.action_names()- assert 'go_to_url' in action_names- assert 'switch_tab' in action_names-- # Verify we're back on the first tab with page1- page = await browser_session.get_current_page()- assert f'{base_url}/page1' in page.url-- async def test_open_new_tab(self, llm, browser_session, base_url):- """Test 'Open new tab' action."""- agent = Agent(- task=f"Open a new tab and go to '{base_url}/page2'.",- llm=llm,- browser_session=browser_session,- )- history = await agent.run(max_steps=2)- action_names = history.action_names()- assert 'go_to_url' in action_names-- # Verify we have at least two tabs- tabs_info = await browser_session.get_tabs_info()- assert len(tabs_info) >= 2-- # Verify the current page is page2- page = await browser_session.get_current_page()- assert f'{base_url}/page2' in page.url-- async def test_extract_page_content(self, llm, browser_session, base_url):- """Test 'Extract page content' action."""- agent = Agent(- task=f"Go to '{base_url}/page1' and extract the page content.",- llm=llm,- browser_session=browser_session,- )- history = await agent.run(max_steps=3)- action_names = history.action_names()- assert 'go_to_url' in action_names- assert 'extract_content' in action_names-- # Verify the extracted content includes some expected text- extracted_content = None- for action_result in history.history[-1].result:- if action_result.extracted_content and 'This is test page 1' in action_result.extracted_content:- extracted_content = action_result.extracted_content- break-- assert extracted_content is not None, 'Expected content not found in extraction'-- async def test_done_action(self, llm, browser_session, base_url):- """Test 'Complete task' action."""- agent = Agent(- task=f"Navigate to '{base_url}/page1' and signal that the task is done.",- llm=llm,- browser_session=browser_session,- )- history = await agent.run(max_steps=3)- action_names = history.action_names()- assert 'go_to_url' in action_names- assert 'done' in action_names-- # Verify the task was marked as successful- assert history.is_successful()-- async def test_scroll_down(self, llm, browser_session, base_url, http_server):- """Test 'Scroll down' action and validate that the page actually scrolled."""- # Create a test page with scrollable content- http_server.expect_request('/scroll-test').respond_with_data(- """- <html>- <head><title>Scroll Test</title>- <style>- body { height: 3000px; }- .marker { position: absolute; }- #top { top: 0; }- #middle { top: 1000px; }- #bottom { top: 2000px; }- </style>- </head>- <body>- <div id="top" class="marker">Top of the page</div>- <div id="middle" class="marker">Middle of the page</div>- <div id="bottom" class="marker">Bottom of the page</div>- </body>- </html>- """,- content_type='text/html',- )-- agent = Agent(- task=f"Go to '{base_url}/scroll-test' and scroll down the page.",- llm=llm,- browser_session=browser_session,- )-- # First go to the page- await agent.run(max_steps=1)- page = await browser_session.get_current_page()-- # Get initial scroll position- initial_scroll_position = await page.evaluate('window.scrollY')-- # Execute a few more steps to allow for scrolling- await agent.run(max_steps=2)-- # Get final scroll position- final_scroll_position = await page.evaluate('window.scrollY')-- # Verify that scrolling occurred- assert final_scroll_position > initial_scroll_position, 'Page did not scroll down'-- # Verify the action was executed- history = agent.history- action_names = history.action_names()- assert 'scroll_down' in action_namesdiff --git a/tests/old/test_cross_origin_iframe_unified_tree.py b/tests/old/test_cross_origin_iframe_unified_tree.pydeleted file mode 100644index 998728c62..000000000--- a/tests/old/test_cross_origin_iframe_unified_tree.py+++ /dev/null@@ -1,407 +0,0 @@-import asyncio--import pytest-from pytest_httpserver import HTTPServer--from browser_use import BrowserSession-from browser_use.browser import BrowserProfile---def cross_origin_iframe_html():- """HTML pages for testing cross-origin iframe handling."""-- # Main page (served on one port)- main_page = """- <!DOCTYPE html>- <html>- <head><title>Main Page</title></head>- <body>- <h1>Main Page Content</h1>- <button id="main-button">Main Button</button>- <input type="text" id="main-input" placeholder="Main input">-- <!-- Cross-origin iframe -->- <iframe- id="frame1"- src="{frame1_url}"- width="600"- height="400"- style="border: 2px solid blue;">- </iframe>-- <p>Some text after iframe</p>- <a href="#" id="main-link">Main Link</a>- </body>- </html>- """-- # First iframe content (served on different port)- frame1_content = """- <!DOCTYPE html>- <html>- <head><title>Frame 1</title></head>- <body style="background: #f0f0f0;">- <h2>Frame 1 Content</h2>- <form id="frame1-form">- <input type="text" id="frame1-input" placeholder="Frame 1 input">- <select id="frame1-select">- <option value="opt1">Option 1</option>- <option value="opt2">Option 2</option>- </select>- <button type="submit" id="frame1-submit">Submit Frame 1</button>- </form>-- <!-- Nested cross-origin iframe -->- <iframe- id="frame2"- src="{frame2_url}"- width="500"- height="300"- style="border: 2px solid green;">- </iframe>- </body>- </html>- """-- # Second nested iframe content (served on yet another port/path)- frame2_content = """- <!DOCTYPE html>- <html>- <head><title>Frame 2</title></head>- <body style="background: #e0e0e0;">- <h3>Frame 2 Content (Nested)</h3>- <div id="frame2-container">- <input type="email" id="frame2-email" placeholder="Email in Frame 2">- <textarea id="frame2-textarea" placeholder="Text area in Frame 2"></textarea>- <button id="frame2-button">Click Me in Frame 2</button>-- <!-- Even deeper nesting -->- <iframe- id="frame3"- src="{frame3_url}"- width="400"- height="200"- style="border: 2px solid red;">- </iframe>- </div>- </body>- </html>- """-- # Third level nested iframe- frame3_content = """- <!DOCTYPE html>- <html>- <head><title>Frame 3</title></head>- <body style="background: #d0d0d0;">- <h4>Frame 3 Content (Deeply Nested)</h4>- <form id="frame3-form">- <input type="password" id="frame3-password" placeholder="Password">- <input type="checkbox" id="frame3-checkbox"> Remember me- <button type="button" id="frame3-button">Deep Button</button>- </form>- </body>- </html>- """-- return {'main': main_page, 'frame1': frame1_content, 'frame2': frame2_content, 'frame3': frame3_content}---def setup_cross_origin_servers(httpserver: HTTPServer, cross_origin_iframe_html):- """Set up multiple HTTP servers to simulate cross-origin iframes."""- import socket-- from pytest_httpserver import HTTPServer as HTTPServerClass-- # Main server (already provided by httpserver fixture)- main_port = httpserver.port-- # Create additional servers for cross-origin simulation- # Find available ports- def get_free_port():- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:- s.bind(('', 0))- s.listen(1)- port = s.getsockname()[1]- return port-- frame1_port = get_free_port()- frame2_port = get_free_port()- frame3_port = get_free_port()-- # Create additional HTTP servers- frame1_server = HTTPServerClass(host='127.0.0.1', port=frame1_port)- frame2_server = HTTPServerClass(host='127.0.0.1', port=frame2_port)- frame3_server = HTTPServerClass(host='127.0.0.1', port=frame3_port)-- frame1_server.start()- frame2_server.start()- frame3_server.start()-- # URLs for each frame- main_url = f'http://127.0.0.1:{main_port}'- frame1_url = f'http://127.0.0.1:{frame1_port}/frame1'- frame2_url = f'http://127.0.0.1:{frame2_port}/frame2'- frame3_url = f'http://127.0.0.1:{frame3_port}/frame3'-- # Set up routes with proper iframe URLs injected- httpserver.expect_request('/').respond_with_data(- cross_origin_iframe_html['main'].format(frame1_url=frame1_url), content_type='text/html'- )-- frame1_server.expect_request('/frame1').respond_with_data(- cross_origin_iframe_html['frame1'].format(frame2_url=frame2_url), content_type='text/html'- )-- frame2_server.expect_request('/frame2').respond_with_data(- cross_origin_iframe_html['frame2'].format(frame3_url=frame3_url), content_type='text/html'- )-- frame3_server.expect_request('/frame3').respond_with_data(cross_origin_iframe_html['frame3'], content_type='text/html')-- yield {- 'main_url': main_url,- 'servers': {'main': httpserver, 'frame1': frame1_server, 'frame2': frame2_server, 'frame3': frame3_server},- }-- # Cleanup- frame1_server.stop()- frame2_server.stop()- frame3_server.stop()---async def test_cross_origin_iframe_detection_current_behavior(setup_cross_origin_servers):- """Test current behavior with cross-origin iframes - demonstrates the problem."""- servers_info = setup_cross_origin_servers- main_url = servers_info['main_url']-- profile = BrowserProfile(headless=True)- session = BrowserSession(browser_profile=profile)- try:- await session.start()- page = await session.get_current_page()- await page.goto(main_url)-- # Wait for all iframes to load- await page.wait_for_load_state('networkidle')- await asyncio.sleep(1) # Extra wait for nested iframes-- # Get the current DOM tree (without CDP)- from browser_use.dom.service import DomService-- dom_service = DomService(page, logger=session.logger)- dom_state = await dom_service.get_clickable_elements(highlight_elements=True)-- # Extract all interactive elements- interactive_elements = []-- def collect_interactive_elements(node, elements_list):- """Recursively collect all interactive elements."""- if hasattr(node, 'is_interactive') and node.is_interactive:- elements_list.append(- {- 'tag': node.tag_name,- 'xpath': node.xpath,- 'highlight_index': node.highlight_index,- 'attributes': node.attributes,- }- )-- if hasattr(node, 'children'):- for child in node.children:- collect_interactive_elements(child, elements_list)-- collect_interactive_elements(dom_state.element_tree, interactive_elements)-- # Check what elements were found- found_ids = {elem['attributes'].get('id') for elem in interactive_elements if 'id' in elem['attributes']}- print(f'\nFound elements: {found_ids}')-- # Expected elements in main frame only (current behavior)- main_frame_ids = {'main-button', 'main-input', 'main-link'}-- # Elements that SHOULD be found but won't be due to cross-origin- cross_origin_ids = {- 'frame1-input',- 'frame1-select',- 'frame1-submit',- 'frame2-email',- 'frame2-textarea',- 'frame2-button',- 'frame3-password',- 'frame3-checkbox',- 'frame3-button',- }-- # Current behavior: only main frame elements are found- assert main_frame_ids.issubset(found_ids), f'Main frame elements missing: {main_frame_ids - found_ids}'-- # This assertion will fail - demonstrating the problem- missing_cross_origin = cross_origin_ids - found_ids- print(f'\nMissing cross-origin elements: {missing_cross_origin}')- assert not missing_cross_origin, f'Cross-origin elements not detected: {missing_cross_origin}'- finally:- await session.close()---async def test_cross_origin_iframe_unified_tree_with_cdp(setup_cross_origin_servers):- """Test that unified tree can detect all elements across cross-origin iframes using CDP."""- servers_info = setup_cross_origin_servers- main_url = servers_info['main_url']-- profile = BrowserProfile(headless=True)- session = BrowserSession(browser_profile=profile)- try:- await session.start()- page = await session.get_current_page()- await page.goto(main_url)-- # Wait for all iframes to load- await page.wait_for_load_state('networkidle')- await asyncio.sleep(1)-- # This is what we want to implement - get unified tree with CDP- # For now, let's test what CDP can access-- # Create CDP session for main frame- cdp_session = await page.context.new_cdp_session(page)-- # Enable required domains- await cdp_session.send('Accessibility.enable')- await cdp_session.send('DOM.enable')-- # Get accessibility tree- ax_tree = await cdp_session.send('Accessibility.getFullAXTree')-- # Check if we can see iframe content- def count_nodes(node, depth=0):- """Count nodes in accessibility tree."""- count = 1- indent = ' ' * depth- role = node.get('role', {}).get('value', 'unknown')- name = node.get('name', {}).get('value', '')- print(f'{indent}{role}: {name}')-- for child_id in node.get('childIds', []):- # In a real implementation, we'd need to look up the child node- count += 1-- return count-- if 'root' in ax_tree:- print('\nAccessibility tree from main frame:')- node_count = count_nodes(ax_tree['root'])- print(f'\nTotal nodes in main frame: {node_count}')-- # Try to access other frames- print(f'\nTotal frames found: {len(page.frames)}')- for i, frame in enumerate(page.frames):- print(f'Frame {i}: {frame.url}')-- # For cross-origin frames, we need separate CDP sessions- if frame != page.main_frame:- try:- frame_cdp = await page.context.new_cdp_session(frame)- await frame_cdp.send('Accessibility.enable')- frame_ax_tree = await frame_cdp.send('Accessibility.getFullAXTree')- print(f' - Successfully got accessibility tree for frame {i}')- await frame_cdp.detach()- except Exception as e:- print(f' - Failed to access frame {i}: {e}')-- # This test demonstrates what we need to implement:- # 1. Create CDP sessions for each frame- # 2. Get accessibility trees from all frames- # 3. Merge them with unique IDs- # 4. Build unified XPaths that cross frame boundaries- finally:- await session.close()---async def test_desired_unified_tree_behavior(setup_cross_origin_servers):- """Test demonstrating the desired behavior with unified tree."""- servers_info = setup_cross_origin_servers- main_url = servers_info['main_url']-- profile = BrowserProfile(headless=True)- session = BrowserSession(browser_profile=profile)- try:- await session.start()- page = await session.get_current_page()- await page.goto(main_url)-- # Wait for all iframes to load- await page.wait_for_load_state('networkidle')- await asyncio.sleep(1)-- # What we want to achieve:- # 1. Get unified tree that includes all frames- unified_tree = {- 'tag': 'body',- 'encoded_id': 'f0:n1',- 'children': [- {'tag': 'h1', 'encoded_id': 'f0:n2'},- {'tag': 'button', 'id': 'main-button', 'encoded_id': 'f0:n3'},- {'tag': 'input', 'id': 'main-input', 'encoded_id': 'f0:n4'},- {- 'tag': 'iframe',- 'id': 'frame1',- 'encoded_id': 'f0:n5',- 'frame_ordinal': 1,- 'children': [- # Frame 1 content with f1: prefix- {'tag': 'h2', 'encoded_id': 'f1:n1'},- {'tag': 'input', 'id': 'frame1-input', 'encoded_id': 'f1:n2'},- {'tag': 'select', 'id': 'frame1-select', 'encoded_id': 'f1:n3'},- {'tag': 'button', 'id': 'frame1-submit', 'encoded_id': 'f1:n4'},- {- 'tag': 'iframe',- 'id': 'frame2',- 'encoded_id': 'f1:n5',- 'frame_ordinal': 2,- 'children': [- # Frame 2 content with f2: prefix- {'tag': 'input', 'id': 'frame2-email', 'encoded_id': 'f2:n1'},- {'tag': 'textarea', 'id': 'frame2-textarea', 'encoded_id': 'f2:n2'},- {'tag': 'button', 'id': 'frame2-button', 'encoded_id': 'f2:n3'},- {- 'tag': 'iframe',- 'id': 'frame3',- 'encoded_id': 'f2:n4',- 'frame_ordinal': 3,- 'children': [- # Frame 3 content with f3: prefix- {'tag': 'input', 'id': 'frame3-password', 'encoded_id': 'f3:n1'},- {'tag': 'input', 'id': 'frame3-checkbox', 'encoded_id': 'f3:n2'},- {'tag': 'button', 'id': 'frame3-button', 'encoded_id': 'f3:n3'},- ],- },- ],- },- ],- },- {'tag': 'p', 'encoded_id': 'f0:n6'},- {'tag': 'a', 'id': 'main-link', 'encoded_id': 'f0:n7'},- ],- }-- # 2. Deep XPaths that include frame traversal- expected_xpaths = {- 'main-button': '//button[@id="main-button"]',- 'frame1-input': '//iframe[@id="frame1"]//input[@id="frame1-input"]',- 'frame2-email': '//iframe[@id="frame1"]//iframe[@id="frame2"]//input[@id="frame2-email"]',- 'frame3-button': '//iframe[@id="frame1"]//iframe[@id="frame2"]//iframe[@id="frame3"]//button[@id="frame3-button"]',- }-- # 3. Ability to click elements in any frame- # await session.click_element_by_encoded_id('f3:n3') # Click button in deepest frame-- print('\nThis test demonstrates the desired unified tree structure')- print('with encoded IDs and deep XPaths for cross-frame navigation')- finally:- await session.close()diff --git a/tests/old/test_dropdown.py b/tests/old/test_dropdown.pydeleted file mode 100644index 59aa6e2f6..000000000--- a/tests/old/test_dropdown.py+++ /dev/null@@ -1,38 +0,0 @@-"""-Test dropdown interaction functionality.-"""--import pytest--from browser_use.agent.service import Agent-from browser_use.agent.views import AgentHistoryList---async def test_dropdown(llm, browser_session):- """Test selecting an option from a dropdown menu."""- agent = Agent(- task=(- 'go to https://codepen.io/geheimschriftstift/pen/mPLvQz and first get all options for the dropdown and then select the 5th option'- ),- llm=llm,- browser_session=browser_session,- )-- try:- history: AgentHistoryList = await agent.run(20)- result = history.final_result()-- # Verify dropdown interaction- assert result is not None- assert 'Duck' in result, "Expected 5th option 'Duck' to be selected"-- # Verify dropdown state- page = await browser_session.get_current_page()- element = await page.query_selector('select')- assert element is not None, 'Dropdown element should exist'-- value = await element.evaluate('el => el.value')- assert value == '5', 'Dropdown should have 5th option selected'-- except Exception as e:- pytest.fail(f'Dropdown test failed: {str(e)}')diff --git a/tests/old/test_dropdown_complex.py b/tests/old/test_dropdown_complex.pydeleted file mode 100644index 5b760bed1..000000000--- a/tests/old/test_dropdown_complex.py+++ /dev/null@@ -1,42 +0,0 @@-"""-Test complex dropdown interaction functionality.-"""--import pytest--from browser_use.agent.service import Agent-from browser_use.agent.views import AgentHistoryList---async def test_dropdown_complex(llm, browser_session):- """Test selecting an option from a complex dropdown menu."""- agent = Agent(- task=(- 'go to https://codepen.io/shyam-king/pen/pvzpByJ and first get all options for the dropdown and then select the json option'- ),- llm=llm,- browser_session=browser_session,- )-- try:- history: AgentHistoryList = await agent.run(20)- result = history.final_result()-- # Verify dropdown interaction- assert result is not None- assert 'json' in result.lower(), "Expected 'json' option to be selected"-- # Verify dropdown state- page = await browser_session.get_current_page()- element = await page.query_selector('.select-selected')- assert element is not None, 'Custom dropdown element should exist'-- text = await element.text_content()- assert 'json' in text.lower(), 'Dropdown should display json option'-- # Verify the selected option's effect- code_element = await page.query_selector('pre code')- assert code_element is not None, 'Code element should be visible when JSON is selected'-- except Exception as e:- pytest.fail(f'Complex dropdown test failed: {str(e)}')diff --git a/tests/old/test_dropdown_error.py b/tests/old/test_dropdown_error.pydeleted file mode 100644index 94bbe507d..000000000--- a/tests/old/test_dropdown_error.py+++ /dev/null@@ -1,37 +0,0 @@-"""-Simple try of the agent.--@dev You need to add OPENAI_API_KEY to your environment variables.-"""--import os-import sys--from browser_use.browser import BrowserProfile, BrowserSession--sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))--from browser_use import Agent, AgentHistoryList-from browser_use.llm import ChatOpenAI--llm = ChatOpenAI(model='gpt-4.1')-browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True))--agent = Agent(- task=('go to https://codepen.io/shyam-king/pen/emOyjKm and select number "4" and return the output of "selected value"'),- llm=llm,- browser_session=browser_session,-)---async def test_dropdown():- await browser_session.start()- try:- history: AgentHistoryList = await agent.run(20)-- result = history.final_result()- assert result is not None- assert '4' in result- print(result)- finally:- await browser_session.stop()diff --git a/tests/old/test_full_screen.py b/tests/old/test_full_screen.pydeleted file mode 100644index e7ee97437..000000000--- a/tests/old/test_full_screen.py+++ /dev/null@@ -1,21 +0,0 @@-import asyncio--from browser_use.browser.types import async_playwright---async def test_full_screen(start_fullscreen: bool, maximize: bool):- async with async_playwright() as p:- browser = await p.chromium.launch(- headless=False,- args=['--start-maximized'],- )- context = await browser.new_context(no_viewport=True, viewport=None)- page = await context.new_page()- await page.goto('https://google.com')-- await asyncio.sleep(10)- await browser.close()---if __name__ == '__main__':- asyncio.run(test_full_screen(False, False))diff --git a/tests/old/test_gif_path.py b/tests/old/test_gif_path.pydeleted file mode 100644index 445ab44ba..000000000--- a/tests/old/test_gif_path.py+++ /dev/null@@ -1,42 +0,0 @@-"""-Simple try of the agent.--@dev You need to add OPENAI_API_KEY to your environment variables.-"""--import os-import sys--from browser_use.browser import BrowserProfile, BrowserSession--sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))--from browser_use import Agent, AgentHistoryList-from browser_use.llm import ChatOpenAI--llm = ChatOpenAI(model='gpt-4.1')--browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True, disable_security=True))--agent = Agent(- task=('go to google.com and search for text "hi there"'),- llm=llm,- browser_session=browser_session,- generate_gif='./google.gif',-)---async def test_gif_path():- if os.path.exists('./google.gif'):- os.unlink('./google.gif')-- await browser_session.start()- try:- history: AgentHistoryList = await agent.run(20)-- result = history.final_result()- assert result is not None-- assert os.path.exists('./google.gif'), 'google.gif was not created'- finally:- await browser_session.stop()diff --git a/tests/old/test_google_sheets_real.py b/tests/old/test_google_sheets_real.pydeleted file mode 100644index a9dbadaa4..000000000--- a/tests/old/test_google_sheets_real.py+++ /dev/null@@ -1,143 +0,0 @@-"""-Real integration tests for Google Sheets actions against the actual Google Sheets website.-Tests the enhanced action registry system with Google Sheets keyboard automation.-Uses the existing Google Sheets actions from the main tools.-"""--import asyncio-import os--import pytest--from browser_use.browser import BrowserProfile, BrowserSession-from browser_use.tools.service import Tools--# Test Google Sheets URL (public read-only spreadsheet for testing)-TEST_GOOGLE_SHEET_URL = 'https://docs.google.com/spreadsheets/d/1INaIcfpYXlMRWO__de61SHFCaqt1lfHlcvtXZPItlpI/edit'---async def browser_session():- """Create a real browser session for testing."""- session = BrowserSession(- browser_profile=BrowserProfile(- executable_path=os.getenv('BROWSER_PATH'),- user_data_dir=None, # Use temporary profile- headless=True,- )- )- async with session:- yield session---def tools():- """Create a tools instance (Google Sheets actions are already registered)."""- return Tools()---async def test_selector_map_basic(browser_session, tools):- """Test that the selector map gets populated on a basic page."""- # Go to a simple page first- page = await browser_session.get_current_page()- await page.goto('https://www.google.com')- await page.wait_for_load_state()-- # Update browser state to populate selector map- await browser_session.get_state_summary(cache_clickable_elements_hashes=False)-- # Check selector map- selector_map = await browser_session.get_selector_map()- print(f'Selector map size: {len(selector_map)}')-- # Should have some elements- assert len(selector_map) > 0, 'No clickable elements found in selector map'---async def test_click_element_basic(browser_session, tools):- """Test basic click element action to verify registry works."""- # Go to a simple page- page = await browser_session.get_current_page()- await page.goto('https://www.google.com')- await page.wait_for_load_state()-- # Update browser state to populate selector map- await browser_session.get_state_summary(cache_clickable_elements_hashes=False)-- # Check selector map- selector_map = await browser_session.get_selector_map()- print(f'Available elements: {list(selector_map.keys())}')-- if len(selector_map) > 0:- # Try to click the first available element- first_index = list(selector_map.keys())[0]- print(f'Trying to click element index: {first_index}')-- result = await tools.registry.execute_action(- 'click_element_by_index', {'index': first_index}, browser_session=browser_session- )-- # Should not have an error about element not existing- print(f'Click result: {result.extracted_content if result.extracted_content else "No content"}')- print(f'Click error: {result.error if result.error else "No error"}')-- # The click might fail for other reasons (like navigation) but shouldn't fail due to "element does not exist"- if result.error:- assert 'Element with index' not in result.error, f'Element indexing failed: {result.error}'- else:- pytest.fail('No clickable elements found - DOM processing issue')---async def test_google_sheets_open(browser_session, tools):- """Test opening a Google Sheet using the existing action."""- # First check what actions are available- available_actions = list(tools.registry.registry.actions.keys())-- # Google Sheets actions are registered with specific names- sheet_actions = [- 'read_sheet_contents',- 'read_cell_contents',- 'update_cell_contents',- 'clear_cell_contents',- 'select_cell_or_range',- 'fallback_input_into_single_selected_cell',- ]-- # Check if sheet actions are available- found_sheet_actions = [action for action in sheet_actions if action in available_actions]-- if not found_sheet_actions:- pytest.skip('No Google Sheets actions found in tools')-- # First navigate to the Google Sheets URL- result = await tools.registry.execute_action(- 'go_to_url', {'url': TEST_GOOGLE_SHEET_URL, 'new_tab': False}, browser_session=browser_session- )-- # Wait for the page to load- await asyncio.sleep(2)-- # Verify we're on the Google Sheets page- page = await browser_session.get_current_page()- assert 'docs.google.com/spreadsheets' in page.url-- # Try to read the sheet contents- if 'read_sheet_contents' in available_actions:- result = await tools.registry.execute_action('read_sheet_contents', {}, browser_session=browser_session)- print(f'Read result: {result.extracted_content if result.extracted_content else "No content"}')- print(f'Read error: {result.error if result.error else "No error"}')---async def test_list_all_actions(browser_session, tools):- """Debug test to list all available actions."""- available_actions = list(tools.registry.registry.actions.keys())- print('All available actions:')- for action in sorted(available_actions):- print(f' - {action}')-- # Just verify the tools has some actions- assert len(available_actions) > 0diff --git a/tests/old/test_mind2web.py b/tests/old/test_mind2web.pydeleted file mode 100644index f0f6c6ee0..000000000--- a/tests/old/test_mind2web.py+++ /dev/null@@ -1,119 +0,0 @@-"""-Test browser automation using Mind2Web dataset tasks with pytest framework.-"""--import json-import os-from typing import Any--import pytest--from browser_use.agent.service import Agent-from browser_use.browser import BrowserProfile, BrowserSession-from browser_use.llm.azure.chat import ChatAzureOpenAI-from browser_use.utils import logger--# Constants-MAX_STEPS = 50-TEST_SUBSET_SIZE = 10---async def browser_session():- browser_session = BrowserSession(- browser_profile=BrowserProfile(- headless=True,- )- )- await browser_session.start()- yield browser_session- await browser_session.stop()---def test_cases() -> list[dict[str, Any]]:- """Load test cases from Mind2Web dataset"""- file_path = os.path.join(os.path.dirname(__file__), 'mind2web_data/processed.json')- logger.info(f'Loading test cases from {file_path}')-- with open(file_path) as f:- data = json.load(f)-- subset = data[:TEST_SUBSET_SIZE]- logger.info(f'Loaded {len(subset)}/{len(data)} test cases')- return subset---def llm():- """Initialize language model for testing"""-- # return ChatAnthropic(model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None)- return ChatAzureOpenAI(- model='gpt-4.1',- )---# run with: pytest -s -v tests/test_mind2web.py:test_random_samples-async def test_random_samples(test_cases: list[dict[str, Any]], llm, browser_session):- """Test a random sampling of tasks across different websites"""- import random-- logger.info('=== Testing Random Samples ===')-- # Take random samples- samples = random.sample(test_cases, 1)-- for i, case in enumerate(samples, 1):- task = f'Go to {case["website"]}.com and {case["confirmed_task"]}'- logger.info(f'--- Random Sample {i}/{len(samples)} ---')- logger.info(f'Task: {task}\n')-- agent = Agent(task, llm, browser_session=browser_session)-- await agent.run()-- logger.info('Validating random sample task...')-- # TODO: Validate the task---def test_dataset_integrity(test_cases):- """Test the integrity of the test dataset"""- logger.info('\n=== Testing Dataset Integrity ===')-- required_fields = ['website', 'confirmed_task', 'action_reprs']- missing_fields = []-- logger.info(f'Checking {len(test_cases)} test cases for required fields')-- for i, case in enumerate(test_cases, 1):- logger.debug(f'Checking case {i}/{len(test_cases)}')-- for field in required_fields:- if field not in case:- missing_fields.append(f'Case {i}: {field}')- logger.warning(f"Missing field '{field}' in case {i}")-- # Type checks- if not isinstance(case.get('confirmed_task'), str):- logger.error(f"Case {i}: 'confirmed_task' must be string")- assert False, 'Task must be string'-- if not isinstance(case.get('action_reprs'), list):- logger.error(f"Case {i}: 'action_reprs' must be list")- assert False, 'Actions must be list'-- if len(case.get('action_reprs', [])) == 0:- logger.error(f"Case {i}: 'action_reprs' must not be empty")- assert False, 'Must have at least one action'-- if missing_fields:- logger.error('Dataset integrity check failed')- assert False, f'Missing fields: {missing_fields}'- else:- logger.info('✅ Dataset integrity check passed')---if __name__ == '__main__':- pytest.main([__file__, '-v'])diff --git a/tests/old/test_react_dropdown.py b/tests/old/test_react_dropdown.pydeleted file mode 100644index f3709253f..000000000--- a/tests/old/test_react_dropdown.py+++ /dev/null@@ -1,44 +0,0 @@-"""-Simple try of the agent.--@dev You need to add OPENAI_API_KEY to your environment variables.-"""--import os-import sys--from browser_use.browser import BrowserProfile, BrowserSession--sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))-import asyncio--from browser_use import Agent, AgentHistoryList-from browser_use.llm import ChatOpenAI--llm = ChatOpenAI(model='gpt-4.1')--browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True, disable_security=True))--agent = Agent(- task=(- 'go to https://codepen.io/shyam-king/pen/ByBJoOv and select "Tiger" dropdown and read the text given in "Selected Animal" box (it can be empty as well)'- ),- llm=llm,- browser_session=browser_session,-)---async def test_dropdown():- await browser_session.start()- try:- history: AgentHistoryList = await agent.run(10)-- result = history.final_result()- assert result is not None- print('result: ', result)- finally:- await browser_session.stop()---if __name__ == '__main__':- asyncio.run(test_dropdown())diff --git a/tests/old/test_self_registered_actions.py b/tests/old/test_self_registered_actions.pydeleted file mode 100644index 77094bad1..000000000--- a/tests/old/test_self_registered_actions.py+++ /dev/null@@ -1,176 +0,0 @@-import pytest-from pydantic import BaseModel--from browser_use.agent.service import Agent-from browser_use.agent.views import AgentHistoryList-from browser_use.browser import BrowserProfile, BrowserSession-from browser_use.llm import ChatAzureOpenAI-from browser_use.tools.service import Tools---async def browser_session():- browser_session = BrowserSession(- browser_profile=BrowserProfile(- headless=True,- )- )- await browser_session.start()- yield browser_session- await browser_session.stop()---async def tools():- """Initialize the tools with self-registered actions"""- tools = Tools()-- # Define custom actions without Pydantic models- @tools.action('Print a message')- def print_message(message: str):- print(f'Message: {message}')- return f'Printed message: {message}'-- @tools.action('Add two numbers')- def add_numbers(a: int, b: int):- result = a + b- return f'The sum is {result}'-- @tools.action('Concatenate strings')- def concatenate_strings(str1: str, str2: str):- result = str1 + str2- return f'Concatenated string: {result}'-- # Define Pydantic models- class SimpleModel(BaseModel):- name: str- age: int-- class Address(BaseModel):- street: str- city: str-- class NestedModel(BaseModel):- user: SimpleModel- address: Address-- # Add actions with Pydantic model arguments- @tools.action('Process simple model', param_model=SimpleModel)- def process_simple_model(model: SimpleModel):- return f'Processed {model.name}, age {model.age}'-- @tools.action('Process nested model', param_model=NestedModel)- def process_nested_model(model: NestedModel):- user_info = f'{model.user.name}, age {model.user.age}'- address_info = f'{model.address.street}, {model.address.city}'- return f'Processed user {user_info} at address {address_info}'-- @tools.action('Process multiple models')- def process_multiple_models(model1: SimpleModel, model2: Address):- return f'Processed {model1.name} living at {model2.street}, {model2.city}'-- yield tools---def llm():- """Initialize language model for testing"""-- # return ChatAnthropic(model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None)- return ChatAzureOpenAI(- model='gpt-4.1',- )---# @pytest.mark.skip(reason="Skipping test for now")-async def test_self_registered_actions_no_pydantic(llm, tools):- """Test self-registered actions with individual arguments"""- agent = Agent(- task="First, print the message 'Hello, World!'. Then, add 10 and 20. Next, concatenate 'foo' and 'bar'.",- llm=llm,- tools=tools,- )- history: AgentHistoryList = await agent.run(max_steps=10)- # Check that custom actions were executed- action_names = history.action_names()-- assert 'print_message' in action_names- assert 'add_numbers' in action_names- assert 'concatenate_strings' in action_names---# @pytest.mark.skip(reason="Skipping test for now")-async def test_mixed_arguments_actions(llm, tools):- """Test actions with mixed argument types"""-- # Define another action during the test- # Test for async actions- @tools.action('Calculate the area of a rectangle')- async def calculate_area(length: float, width: float):- area = length * width- return f'The area is {area}'-- agent = Agent(- task='Calculate the area of a rectangle with length 5.5 and width 3.2.',- llm=llm,- tools=tools,- )- history = await agent.run(max_steps=5)-- # Check that the action was executed- action_names = history.action_names()-- assert 'calculate_area' in action_names- # check result- correct = 'The area is 17.6'- for content in history.extracted_content():- if correct in content:- break- else:- pytest.fail(f'{correct} not found in extracted content')---async def test_pydantic_simple_model(llm, tools):- """Test action with a simple Pydantic model argument"""- agent = Agent(- task="Process a simple model with name 'Alice' and age 30.",- llm=llm,- tools=tools,- )- history = await agent.run(max_steps=5)-- # Check that the action was executed- action_names = history.action_names()-- assert 'process_simple_model' in action_names- correct = 'Processed Alice, age 30'- for content in history.extracted_content():- if correct in content:- break- else:- pytest.fail(f'{correct} not found in extracted content')---async def test_pydantic_nested_model(llm, tools):- """Test action with a nested Pydantic model argument"""- agent = Agent(- task="Process a nested model with user name 'Bob', age 25, living at '123 Maple St', 'Springfield'.",- llm=llm,- tools=tools,- )- history = await agent.run(max_steps=5)-- # Check that the action was executed- action_names = history.action_names()-- assert 'process_nested_model' in action_names- correct = 'Processed user Bob, age 25 at address 123 Maple St, Springfield'- for content in history.extracted_content():- if correct in content:- break- else:- pytest.fail(f'{correct} not found in extracted content')---# run this file with:-# pytest tests/test_self_registered_actions.py --capture=nodiff --git a/tests/old/test_tool_calling_methods.py b/tests/old/test_tool_calling_methods.pydeleted file mode 100644index 6328da6de..000000000--- a/tests/old/test_tool_calling_methods.py+++ /dev/null@@ -1,127 +0,0 @@-"""-Test script for tool calling methods to ensure proper handling of different LLM method arguments.-"""--from unittest.mock import Mock--import pytest-from langchain_core.language_models.chat_models import BaseChatModel--from browser_use.agent.service import Agent---class TestToolCallingMethods:- """Tests for different tool calling methods handling."""-- @pytest.fixture- def mock_llm_with_structured_output(self):- """Create a mock LLM that tracks with_structured_output calls."""- mock_llm = Mock(spec=BaseChatModel)-- # Track calls to with_structured_output- structured_output_calls = []-- def mock_with_structured_output(schema, include_raw=True, method=None):- structured_output_calls.append({'schema': schema, 'include_raw': include_raw, 'method': method})-- # Return a mock that can be invoked- mock_structured = Mock()- mock_structured.invoke = Mock(return_value={'parsed': None, 'raw': Mock(content='test')})- mock_structured.ainvoke = Mock(return_value={'parsed': None, 'raw': Mock(content='test')})- return mock_structured-- mock_llm.with_structured_output = mock_with_structured_output- mock_llm.structured_output_calls = structured_output_calls- mock_llm.invoke = Mock(return_value=Mock(content='{"answer": "paris"}'))-- return mock_llm-- async def test_tools_method_error(self, mock_llm_with_structured_output):- """Test that 'tools' method causes the expected error."""- # Create agent with 'tools' method- agent = Agent(- task='Test task',- llm=mock_llm_with_structured_output,- tool_calling_method='tools',- )-- # The error should occur during initialization when _test_tool_calling_method is called- # Check that with_structured_output was called with 'tools' method- assert len(mock_llm_with_structured_output.structured_output_calls) > 0-- # Find the call that used 'tools' method- tools_call = next(- (call for call in mock_llm_with_structured_output.structured_output_calls if call['method'] == 'tools'), None- )- assert tools_call is not None, "Expected with_structured_output to be called with method='tools'"-- async def test_function_calling_method_works(self, mock_llm_with_structured_output):- """Test that 'function_calling' method works correctly."""- # Create agent with 'function_calling' method- agent = Agent(- task='Test task',- llm=mock_llm_with_structured_output,- tool_calling_method='function_calling',- )-- # Check that with_structured_output was called with 'function_calling' method- assert len(mock_llm_with_structured_output.structured_output_calls) > 0-- # Find the call that used 'function_calling' method- fc_call = next(- (call for call in mock_llm_with_structured_output.structured_output_calls if call['method'] == 'function_calling'),- None,- )- assert fc_call is not None, "Expected with_structured_output to be called with method='function_calling'"-- async def test_json_mode_method_works(self, mock_llm_with_structured_output):- """Test that 'json_mode' method works correctly."""- # Create agent with 'json_mode' method- agent = Agent(- task='Test task',- llm=mock_llm_with_structured_output,- tool_calling_method='json_mode',- )-- # For json_mode, it should not call with_structured_output during testing- # because it uses raw mode- # Check the calls- json_mode_calls = [- call for call in mock_llm_with_structured_output.structured_output_calls if call['method'] == 'json_mode'- ]- # json_mode is handled specially and doesn't use with_structured_output in _test_tool_calling_method- assert len(json_mode_calls) == 0-- async def test_raw_method_works(self, mock_llm_with_structured_output):- """Test that 'raw' method works correctly."""- # Create agent with 'raw' method- agent = Agent(- task='Test task',- llm=mock_llm_with_structured_output,- tool_calling_method='raw',- )-- # For raw mode, it should not call with_structured_output during testing- # Check the calls- raw_calls = [call for call in mock_llm_with_structured_output.structured_output_calls if call['method'] == 'raw']- # raw is handled specially and doesn't use with_structured_output in _test_tool_calling_method- assert len(raw_calls) == 0-- async def test_auto_method_selection(self, mock_llm_with_structured_output):- """Test that 'auto' method selects appropriate method based on LLM."""- # Mock the agent to simulate Azure OpenAI with GPT-4- agent = Agent(- task='Test task',- llm=mock_llm_with_structured_output,- tool_calling_method='auto',- )-- # Monkey patch to simulate Azure OpenAI- agent.chat_model_library = 'AzureChatOpenAI'- agent.chat_model_name = 'gpt-4-1106-preview'-- # Call _get_tool_calling_method_for_model to see what it returns- method = agent._get_tool_calling_method_for_model()-- # For Azure OpenAI with GPT-4, it should return 'tools'- assert method == 'tools'diff --git a/tests/old/test_vision.py b/tests/old/test_vision.pydeleted file mode 100644index 1d75fb847..000000000--- a/tests/old/test_vision.py+++ /dev/null@@ -1,57 +0,0 @@-"""-Simple try of the agent.--@dev You need to add OPENAI_API_KEY to your environment variables.-"""--import os-import sys-from pprint import pprint--import pytest--sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))---from browser_use import Agent, AgentHistoryList, BrowserSession, Tools-from browser_use.llm import ChatOpenAI--llm = ChatOpenAI(model='gpt-4.1')-tools = Tools()--# use this test to ask the model questions about the page like-# which color do you see for bbox labels, list all with their label-# what's the smallest bboxes with labels and--[email protected](description='explain what you see on the screen and ask user for input')-async def explain_screen(text: str) -> str:- pprint(text)- answer = input('\nuser input next question: \n')- return answer--[email protected](description='done')-async def done(text: str) -> str:- # pprint(text)- return 'call explain_screen'--[email protected](reason='this is for local testing only')-async def test_vision():- from browser_use.browser.profile import BrowserProfile-- profile = BrowserProfile(headless=True, user_data_dir=None)- browser_session = BrowserSession(browser_profile=profile)- await browser_session.start()- try:- agent = Agent(- task='call explain_screen all the time the user asks you questions e.g. about the page like bbox which you see are labels - your task is to explain it and get the next question',- llm=llm,- tools=tools,- browser_session=browser_session,- )- history: AgentHistoryList = await agent.run(20)- finally:- # Make sure to close the browser- await browser_session.stop()diff --git a/tests/old/test_wait_for_element.py b/tests/old/test_wait_for_element.pydeleted file mode 100644index 4264749af..000000000--- a/tests/old/test_wait_for_element.py+++ /dev/null@@ -1,70 +0,0 @@-import asyncio-import os-import sys--from browser_use.llm.openai.chat import ChatOpenAI--project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))-if project_root not in sys.path:- sys.path.insert(0, project_root)--import pytest-from dotenv import load_dotenv--# Third-party imports-from browser_use import Agent, Tools--# Local imports-from browser_use.browser import BrowserProfile, BrowserSession--# Load environment variables.-load_dotenv()--# Initialize language model and tools.-llm = ChatOpenAI(model='gpt-4.1')-tools = Tools()--[email protected](reason='this is for local testing only')-async def test_wait_for_element():- """Test 'Wait for element' action."""-- initial_actions = [- {'go_to_url': {'url': 'https://pypi.org/', 'new_tab': True}},- # Uncomment the line below to include the wait action in initial actions.- # {'wait_for_element': {'selector': '#search', 'timeout': 30}},- ]-- # Set up the browser session.- browser_session = BrowserSession(browser_profile=BrowserProfile(headless=True, disable_security=True))- await browser_session.start()-- try:- # Create the agent with the task.- agent = Agent(- task="Wait for element '#search' to be visible with a timeout of 30 seconds.",- llm=llm,- browser_session=browser_session,- initial_actions=initial_actions,- tools=tools,- )-- # Run the agent for a few steps to trigger navigation and then the wait action.- history = await agent.run(max_steps=3)- action_names = history.action_names()-- # Ensure that the wait_for_element action was executed.- assert 'wait_for_element' in action_names, 'Expected wait_for_element action to be executed.'-- # Verify that the #search element is visible by querying the page.- page = await browser_session.get_current_page()- header_handle = await page.query_selector('#search')- assert header_handle is not None, 'Expected to find a #search element on the page.'- is_visible = await header_handle.is_visible()- assert is_visible, 'Expected the #search element to be visible.'- finally:- await browser_session.stop()---if __name__ == '__main__':- asyncio.run(test_wait_for_element())