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 dead tests
Nick Sweeting1b18e15a85d2
diff --git a/tests/ci/test_browser_session_start.py b/tests/ci/test_browser_session_start.pyindex b99c7ad5d..62e179cf2 100644--- a/tests/ci/test_browser_session_start.py+++ b/tests/ci/test_browser_session_start.py@@ -24,7 +24,6 @@ from browser_use.browser.profile import ()from browser_use.browser.session import BrowserSessionfrom browser_use.config import CONFIG-from tests.ci.conftest import create_mock_llm# Set up test logginglogger = logging.getLogger('browser_session_start_tests')@@ -643,191 +642,191 @@ class TestBrowserSessionReusePatterns:finally:await reused_session.kill()- async def test_parallel_agents_same_browser_multiple_tabs(self, httpserver):- """Test Parallel Agents, Same Browser, Multiple Tabs pattern"""-- from browser_use import Agent, BrowserSession-- # Create a shared browser session- with tempfile.NamedTemporaryFile(suffix='.json', delete=False, mode='w') as f:- # Write minimal valid storage state- f.write('{"cookies": [], "origins": []}')- storage_state_path = f.name-- # Convert to Path object to fix storage state type error- from pathlib import Path-- storage_state_path = Path(storage_state_path)-- shared_browser = BrowserSession(- browser_profile=BrowserProfile(- storage_state=storage_state_path,- user_data_dir=None,- keep_alive=True,- headless=True,- ),- )-- try:- # Set up httpserver- httpserver.expect_request('/').respond_with_data('<html><body>Test page</body></html>')- test_url = httpserver.url_for('/')-- # Start the session before passing it to agents- await shared_browser.start()-- # Create action sequences for each agent- # Each agent creates a new tab then completes- tab_creation_action = (- """- {- "thinking": "null",- "evaluation_previous_goal": "Starting the task",- "memory": "Need to create a new tab",- "next_goal": "Create a new tab to work in",- "action": [- {- "go_to_url": {- "url": "%s",- "new_tab": true- }- }- ]- }- """- % test_url- )-- done_action = """- {- "thinking": "null",- "evaluation_previous_goal": "Tab created",- "memory": "Task completed in new tab",- "next_goal": "Complete the task",- "action": [- {- "done": {- "text": "Task completed successfully",- "success": true- }- }- ]- }- """-- # Create 3 agents sharing the same browser session- # Each gets its own mock LLM with the same action sequence- mock_llm1 = create_mock_llm([tab_creation_action, done_action])- mock_llm2 = create_mock_llm([tab_creation_action, done_action])- mock_llm3 = create_mock_llm([tab_creation_action, done_action])-- agent1 = Agent(- task='First parallel task...',- llm=mock_llm1,- browser_session=shared_browser,- enable_memory=False, # Disable memory for tests- )- agent2 = Agent(- task='Second parallel task...',- llm=mock_llm2,- browser_session=shared_browser,- enable_memory=False, # Disable memory for tests- )- agent3 = Agent(- task='Third parallel task...',- llm=mock_llm3,- browser_session=shared_browser,- enable_memory=False, # Disable memory for tests- )-- # Run all agents in parallel- results = await asyncio.gather(agent1.run(), agent2.run(), agent3.run(), return_exceptions=True)-- # Check if any agents failed- for i, result in enumerate(results):- if isinstance(result, Exception):- raise AssertionError(f'Agent {i + 1} failed with error: {result}')-- # Verify all agents used the same browser session (using __eq__ to check browser_pid, cdp_url, wss_url)- # Debug: print the browser sessions to see what's different- print(f'Agent1 session: {agent1.browser_session}')- print(f'Agent2 session: {agent2.browser_session}')- print(f'Agent3 session: {agent3.browser_session}')- print(f'Shared session: {shared_browser}')-- # Check each pair individually- assert agent1.browser_session == agent2.browser_session, (- f'agent1 != agent2: {agent1.browser_session} != {agent2.browser_session}'- )- assert agent2.browser_session == agent3.browser_session, (- f'agent2 != agent3: {agent2.browser_session} != {agent3.browser_session}'- )- assert agent1.browser_session == shared_browser, f'agent1 != shared: {agent1.browser_session} != {shared_browser}'- assert shared_browser.initialized-- # Give a small delay to ensure all tabs are fully created- await asyncio.sleep(0.5)-- # Verify multiple tabs were created- tabs_info = await shared_browser.get_tabs_info()- print(f'Number of tabs: {len(tabs_info)}')- for i, tab in enumerate(tabs_info):- print(f'Tab {i}: {tab}')-- # Should have at least 3 tabs (one per agent)- # In some cases, there might be more tabs if the initial about:blank tab is still open- assert len(tabs_info) >= 3, f'Expected at least 3 tabs, but found {len(tabs_info)}: {tabs_info}'-- finally:- await shared_browser.kill()- storage_state_path.unlink(missing_ok=True)-- async def test_parallel_agents_same_browser_same_tab(self, mock_llm, httpserver):- """Test Parallel Agents, Same Browser, Same Tab pattern (not recommended)"""- from browser_use import Agent, BrowserSession-- # Create a browser session and start it first- shared_browser = BrowserSession(- browser_profile=BrowserProfile(- user_data_dir=None,- headless=True,- keep_alive=True, # Keep the browser alive for reuse- ),- )-- try:- await shared_browser.start()-- # Create agents sharing the same browser session- # They will share the same tab since we're not creating new tabs- agent1 = Agent(- task='Fill out the form in section A...',- llm=mock_llm,- browser_session=shared_browser,- enable_memory=False, # Disable memory for tests- )- agent2 = Agent(- task='Fill out the form in section B...',- llm=mock_llm,- browser_session=shared_browser,- enable_memory=False, # Disable memory for tests- )-- # Set up httpserver and navigate to a page before running agents- httpserver.expect_request('/').respond_with_data('<html><body>Test page</body></html>')- page = await shared_browser.get_current_page()- await page.goto(httpserver.url_for('/'), wait_until='domcontentloaded', timeout=3000)-- # Run agents in parallel (may interfere with each other)- _results = await asyncio.gather(agent1.run(), agent2.run(), return_exceptions=True)-- # Verify both agents used the same browser session- assert agent1.browser_session == agent2.browser_session- assert agent1.browser_session == shared_browser-- finally:- # Clean up- await shared_browser.kill()+ # async def test_parallel_agents_same_browser_multiple_tabs(self, httpserver):+ # """Test Parallel Agents, Same Browser, Multiple Tabs pattern"""++ # from browser_use import Agent, BrowserSession++ # # Create a shared browser session+ # with tempfile.NamedTemporaryFile(suffix='.json', delete=False, mode='w') as f:+ # # Write minimal valid storage state+ # f.write('{"cookies": [], "origins": []}')+ # storage_state_path = f.name++ # # Convert to Path object to fix storage state type error+ # from pathlib import Path++ # storage_state_path = Path(storage_state_path)++ # shared_browser = BrowserSession(+ # browser_profile=BrowserProfile(+ # storage_state=storage_state_path,+ # user_data_dir=None,+ # keep_alive=True,+ # headless=True,+ # ),+ # )++ # try:+ # # Set up httpserver+ # httpserver.expect_request('/').respond_with_data('<html><body>Test page</body></html>')+ # test_url = httpserver.url_for('/')++ # # Start the session before passing it to agents+ # await shared_browser.start()++ # # Create action sequences for each agent+ # # Each agent creates a new tab then completes+ # tab_creation_action = (+ # """+ # {+ # "thinking": "null",+ # "evaluation_previous_goal": "Starting the task",+ # "memory": "Need to create a new tab",+ # "next_goal": "Create a new tab to work in",+ # "action": [+ # {+ # "go_to_url": {+ # "url": "%s",+ # "new_tab": true+ # }+ # }+ # ]+ # }+ # """+ # % test_url+ # )++ # done_action = """+ # {+ # "thinking": "null",+ # "evaluation_previous_goal": "Tab created",+ # "memory": "Task completed in new tab",+ # "next_goal": "Complete the task",+ # "action": [+ # {+ # "done": {+ # "text": "Task completed successfully",+ # "success": true+ # }+ # }+ # ]+ # }+ # """++ # # Create 3 agents sharing the same browser session+ # # Each gets its own mock LLM with the same action sequence+ # mock_llm1 = create_mock_llm([tab_creation_action, done_action])+ # mock_llm2 = create_mock_llm([tab_creation_action, done_action])+ # mock_llm3 = create_mock_llm([tab_creation_action, done_action])++ # agent1 = Agent(+ # task='First parallel task...',+ # llm=mock_llm1,+ # browser_session=shared_browser,+ # enable_memory=False, # Disable memory for tests+ # )+ # agent2 = Agent(+ # task='Second parallel task...',+ # llm=mock_llm2,+ # browser_session=shared_browser,+ # enable_memory=False, # Disable memory for tests+ # )+ # agent3 = Agent(+ # task='Third parallel task...',+ # llm=mock_llm3,+ # browser_session=shared_browser,+ # enable_memory=False, # Disable memory for tests+ # )++ # # Run all agents in parallel+ # results = await asyncio.gather(agent1.run(), agent2.run(), agent3.run(), return_exceptions=True)++ # # Check if any agents failed+ # for i, result in enumerate(results):+ # if isinstance(result, Exception):+ # raise AssertionError(f'Agent {i + 1} failed with error: {result}')++ # # Verify all agents used the same browser session (using __eq__ to check browser_pid, cdp_url, wss_url)+ # # Debug: print the browser sessions to see what's different+ # print(f'Agent1 session: {agent1.browser_session}')+ # print(f'Agent2 session: {agent2.browser_session}')+ # print(f'Agent3 session: {agent3.browser_session}')+ # print(f'Shared session: {shared_browser}')++ # # Check each pair individually+ # assert agent1.browser_session == agent2.browser_session, (+ # f'agent1 != agent2: {agent1.browser_session} != {agent2.browser_session}'+ # )+ # assert agent2.browser_session == agent3.browser_session, (+ # f'agent2 != agent3: {agent2.browser_session} != {agent3.browser_session}'+ # )+ # assert agent1.browser_session == shared_browser, f'agent1 != shared: {agent1.browser_session} != {shared_browser}'+ # assert shared_browser.initialized++ # # Give a small delay to ensure all tabs are fully created+ # await asyncio.sleep(0.5)++ # # Verify multiple tabs were created+ # tabs_info = await shared_browser.get_tabs_info()+ # print(f'Number of tabs: {len(tabs_info)}')+ # for i, tab in enumerate(tabs_info):+ # print(f'Tab {i}: {tab}')++ # # Should have at least 3 tabs (one per agent)+ # # In some cases, there might be more tabs if the initial about:blank tab is still open+ # assert len(tabs_info) >= 3, f'Expected at least 3 tabs, but found {len(tabs_info)}: {tabs_info}'++ # finally:+ # await shared_browser.kill()+ # storage_state_path.unlink(missing_ok=True)++ # async def test_parallel_agents_same_browser_same_tab(self, mock_llm, httpserver):+ # """Test Parallel Agents, Same Browser, Same Tab pattern (not recommended)"""+ # from browser_use import Agent, BrowserSession++ # # Create a browser session and start it first+ # shared_browser = BrowserSession(+ # browser_profile=BrowserProfile(+ # user_data_dir=None,+ # headless=True,+ # keep_alive=True, # Keep the browser alive for reuse+ # ),+ # )++ # try:+ # await shared_browser.start()++ # # Create agents sharing the same browser session+ # # They will share the same tab since we're not creating new tabs+ # agent1 = Agent(+ # task='Fill out the form in section A...',+ # llm=mock_llm,+ # browser_session=shared_browser,+ # enable_memory=False, # Disable memory for tests+ # )+ # agent2 = Agent(+ # task='Fill out the form in section B...',+ # llm=mock_llm,+ # browser_session=shared_browser,+ # enable_memory=False, # Disable memory for tests+ # )++ # # Set up httpserver and navigate to a page before running agents+ # httpserver.expect_request('/').respond_with_data('<html><body>Test page</body></html>')+ # page = await shared_browser.get_current_page()+ # await page.goto(httpserver.url_for('/'), wait_until='domcontentloaded', timeout=3000)++ # # Run agents in parallel (may interfere with each other)+ # _results = await asyncio.gather(agent1.run(), agent2.run(), return_exceptions=True)++ # # Verify both agents used the same browser session+ # assert agent1.browser_session == agent2.browser_session+ # assert agent1.browser_session == shared_browser++ # finally:+ # # Clean up+ # await shared_browser.kill()async def test_parallel_agents_same_profile_different_browsers(self, mock_llm):"""Test Parallel Agents, Same Profile, Different Browsers pattern (recommended)"""