Skip to content

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

clean up ci tests and rename them for clarity

Nick Sweeting07772c8d1db2
diff --git a/pytest.ini b/pytest.ini
deleted file mode 100644
index 8715c46f8..000000000
--- a/pytest.ini
+++ /dev/null
@@ -1,29 +0,0 @@
-[pytest]
-markers =
- slow: marks tests as slow (deselect with '-m "not slow"')
- integration: marks tests as integration tests
- unit: marks tests as unit tests
- asyncio: mark tests as async tests
-
-testpaths =
- tests
-
-python_files =
- test_*.py
- *_test.py
-
-addopts =
- -v
- --strict-markers
- --tb=short
-
-asyncio_mode = auto
-asyncio_default_fixture_loop_scope = function
-log_cli = true
-; log_cli_level = DEBUG
-log_cli_format = %(levelname)-8s [%(name)s] %(message)s
-filterwarnings =
- ignore::pytest.PytestDeprecationWarning
- ignore::DeprecationWarning
-
-log_level = INFO
diff --git a/tests/ci/test_url_allowlist_security.py b/tests/ci/test_browser_session_allowed_domains.py
similarity index 100%
rename from tests/ci/test_url_allowlist_security.py
rename to tests/ci/test_browser_session_allowed_domains.py
diff --git a/tests/ci/test_debug_selector_map.py b/tests/ci/test_browser_session_element_cache.py
similarity index 100%
rename from tests/ci/test_debug_selector_map.py
rename to tests/ci/test_browser_session_element_cache.py
diff --git a/tests/ci/test_browser_session_param.py b/tests/ci/test_browser_session_param.py
index e88ad5d2f..87ea2f89b 100644
--- a/tests/ci/test_browser_session_param.py
+++ b/tests/ci/test_browser_session_param.py
@@ -237,7 +237,6 @@ async def main(browser_session):
import pytest
async def test_browser_session_parameter_issue(browser_session):
"""Test that the browser_session parameter issue is fixed."""
# Run the main test logic
diff --git a/tests/ci/test_browser.py b/tests/ci/test_browser_via_cdp.py
similarity index 97%
rename from tests/ci/test_browser.py
rename to tests/ci/test_browser_via_cdp.py
index d7ed1bfbe..b00fa904a 100644
--- a/tests/ci/test_browser.py
+++ b/tests/ci/test_browser_via_cdp.py
@@ -4,7 +4,6 @@ from playwright.async_api import async_playwright
from browser_use.browser import BrowserSession
async def test_connection_via_cdp(monkeypatch):
browser_session = BrowserSession(
cdp_url='http://localhost:9898',
diff --git a/tests/ci/test_controller.py b/tests/ci/test_controller.py
index c249ebd79..e6c8cfd3f 100644
--- a/tests/ci/test_controller.py
+++ b/tests/ci/test_controller.py
@@ -27,13 +27,6 @@ from browser_use.controller.views import (
class TestControllerIntegration:
"""Integration tests for Controller using actual browser instances."""
- @pytest.fixture(scope='module')
- def event_loop(self):
- """Create and provide an event loop for async tests."""
- loop = asyncio.get_event_loop_policy().new_event_loop()
- yield loop
- loop.close()
-
@pytest.fixture(scope='module')
def http_server(self):
"""Create and provide a test HTTP server that serves static content."""
@@ -81,8 +74,8 @@ class TestControllerIntegration:
"""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, event_loop):
+ @pytest.fixture
+ async def browser_session(self):
"""Create and provide a Browser instance with security disabled."""
browser_session = BrowserSession(
# browser_profile=BrowserProfile(),
@@ -98,7 +91,6 @@ class TestControllerIntegration:
"""Create and provide a Controller instance."""
return Controller()
- @pytest.mark.asyncio
async def test_go_to_url_action(self, controller, browser_session, base_url):
"""Test that GoToUrlAction navigates to the specified URL."""
# Create action model for go_to_url
@@ -121,7 +113,6 @@ class TestControllerIntegration:
page = await browser_session.get_current_page()
assert f'{base_url}/page1' in page.url
- @pytest.mark.asyncio
async def test_scroll_actions(self, controller, browser_session, base_url):
"""Test that scroll actions correctly scroll the page."""
# First navigate to a page
@@ -158,7 +149,6 @@ class TestControllerIntegration:
assert isinstance(result, ActionResult)
assert 'Scrolled up' in result.extracted_content
- @pytest.mark.asyncio
async def test_registry_actions(self, controller, browser_session):
"""Test that the registry contains the expected default actions."""
# Check that common actions are registered
@@ -181,7 +171,6 @@ class TestControllerIntegration:
assert controller.registry.registry.actions[action].function is not None
assert controller.registry.registry.actions[action].description is not None
- @pytest.mark.asyncio
async def test_custom_action_registration(self, controller, browser_session, base_url):
"""Test registering a custom action and executing it."""
@@ -216,7 +205,6 @@ class TestControllerIntegration:
assert 'Custom action executed with: test_value on' in result.extracted_content
assert f'{base_url}/page1' in result.extracted_content
- @pytest.mark.asyncio
async def test_input_text_action(self, controller, browser_session, base_url, http_server):
"""Test that InputTextAction correctly inputs text into form fields."""
# Set up search form endpoint for this test
@@ -273,7 +261,6 @@ class TestControllerIntegration:
# If it fails due to DOM issues, that's expected in a test environment
assert 'Element index' in str(e) or 'does not exist' in str(e)
- @pytest.mark.asyncio
async def test_error_handling(self, controller, browser_session):
"""Test error handling when an action fails."""
# Create an action with an invalid index
@@ -289,7 +276,6 @@ class TestControllerIntegration:
# Verify that an appropriate error is raised
assert 'does not exist' in str(excinfo.value) or 'Element with index' in str(excinfo.value)
- @pytest.mark.asyncio
async def test_wait_action(self, controller, browser_session):
"""Test that the wait action correctly waits for the specified duration."""
@@ -329,7 +315,6 @@ class TestControllerIntegration:
# Verify that at least 1 second has passed
assert end_time - start_time >= 0.9 # Allow some timing margin
- @pytest.mark.asyncio
async def test_go_back_action(self, controller, browser_session, base_url):
"""Test that go_back action navigates to the previous page."""
# Navigate to first page
@@ -378,7 +363,6 @@ class TestControllerIntegration:
# Try to verify we're back on the first page, but don't fail the test if not
assert f'{base_url}/page1' in final_url, f'Expected to return to page1 but got {final_url}'
- @pytest.mark.asyncio
async def test_navigation_chain(self, controller, browser_session, base_url):
"""Test navigating through multiple pages and back through history."""
# Set up a chain of navigation: Home -> Page1 -> Page2
@@ -410,7 +394,6 @@ class TestControllerIntegration:
page = await browser_session.get_current_page()
assert expected_url in page.url
- @pytest.mark.asyncio
async def test_concurrent_tab_operations(self, controller, browser_session, base_url):
"""Test operations across multiple tabs."""
# Create two tabs with different content
@@ -461,7 +444,6 @@ class TestControllerIntegration:
assert len(tabs_info) == 1
assert urls[0] in tabs_info[0].url
- @pytest.mark.asyncio
async def test_excluded_actions(self, browser_session):
"""Test that excluded actions are not registered."""
# Create controller with excluded actions
@@ -475,7 +457,6 @@ class TestControllerIntegration:
assert 'go_to_url' in excluded_controller.registry.registry.actions
assert 'click_element_by_index' in excluded_controller.registry.registry.actions
- @pytest.mark.asyncio
async def test_search_google_action(self, controller, browser_session, base_url):
"""Test the search_google action."""
@@ -497,7 +478,6 @@ class TestControllerIntegration:
page = await browser_session.get_current_page()
assert page.url is not None and 'Python' in page.url
- @pytest.mark.asyncio
async def test_done_action(self, controller, browser_session, base_url):
"""Test that DoneAction completes a task and reports success or failure."""
# First navigate to a page
@@ -541,7 +521,6 @@ class TestControllerIntegration:
assert result.is_done is True
assert result.error is None
- @pytest.mark.asyncio
async def test_drag_drop_action(self, controller, browser_session, base_url, http_server):
"""Test that DragDropAction correctly drags and drops elements."""
# Set up drag and drop test page for this test
@@ -769,7 +748,6 @@ class TestControllerIntegration:
assert drag_succeeded, "Drag and drop events weren't fired correctly"
- @pytest.mark.asyncio
async def test_send_keys_action(self, controller, browser_session, base_url, http_server):
"""Test SendKeysAction using a controlled local HTML file."""
# Set up keyboard test page for this test
@@ -973,7 +951,6 @@ class TestControllerIntegration:
input_value = await page.evaluate('() => document.getElementById("textInput").value')
assert input_value == test_text, "Input value shouldn't have changed after tabbing"
- @pytest.mark.asyncio
async def test_get_dropdown_options(self, controller, browser_session, base_url, http_server):
"""Test that get_dropdown_options correctly retrieves options from a dropdown."""
# Add route for dropdown test page
@@ -1084,7 +1061,6 @@ class TestControllerIntegration:
f"Option at index {i} has wrong value: expected '{expected['value']}', got '{actual['value']}'"
)
- @pytest.mark.asyncio
async def test_select_dropdown_option(self, controller, browser_session, base_url, http_server):
"""Test that select_dropdown_option correctly selects an option from a dropdown."""
# Add route for dropdown test page
@@ -1159,7 +1135,6 @@ class TestControllerIntegration:
selected_value = await page.evaluate("document.getElementById('test-dropdown').value")
assert selected_value == 'option2' # Second Option has value "option2"
- @pytest.mark.asyncio
async def test_extract_content_action(self, controller, browser_session, base_url, http_server):
"""Test the default extract_content action with mixed parameter ordering."""
# Set up a test page with specific content
@@ -1257,7 +1232,6 @@ class TestControllerIntegration:
assert action_model.extract_content['goal'] == 'Extract all product information including links'
assert action_model.extract_content['include_links'] is True
- @pytest.mark.asyncio
async def test_click_element_by_index(self, controller, browser_session, base_url, http_server):
"""Test that click_element_by_index correctly clicks an element and handles different outcomes."""
# Add route for clickable elements test page
diff --git a/tests/ci/test_browser_session.py b/tests/ci/test_special_action_parameter_injection.py
similarity index 100%
rename from tests/ci/test_browser_session.py
rename to tests/ci/test_special_action_parameter_injection.py
diff --git a/tests/ci/test_tab_management.py b/tests/ci/test_tab_management.py
index 7d5e05dc8..57f970549 100644
--- a/tests/ci/test_tab_management.py
+++ b/tests/ci/test_tab_management.py
@@ -20,13 +20,6 @@ logger.setLevel(logging.DEBUG)
class TestTabManagement:
"""Tests for the tab management system with separate agent_current_page and human_current_page references."""
- @pytest.fixture(scope='module')
- def event_loop(self):
- """Create and provide an event loop for async tests."""
- loop = asyncio.get_event_loop_policy().new_event_loop()
- yield loop
- loop.close()
-
@pytest.fixture(scope='module')
def http_server(self):
"""Create and provide a test HTTP server that serves static content."""
@@ -51,7 +44,7 @@ class TestTabManagement:
server.stop()
@pytest.fixture(scope='module')
- async def browser_profile(self, event_loop):
+ async def browser_profile(self):
"""Create and provide a BrowserProfile with security disabled."""
profile = BrowserProfile(headless=True)
yield profile
@@ -191,7 +184,6 @@ class TestTabManagement:
# Tab management tests
- @pytest.mark.asyncio
async def test_initial_values(self, browser_session, base_url):
"""Test that open_tab correctly updates both tab references."""
@@ -210,7 +202,6 @@ class TestTabManagement:
assert current_tab is not None
assert current_tab.url == 'about:blank'
- @pytest.mark.asyncio
async def test_agent_changes_tab(self, browser_session, base_url):
"""Test that agent_current_page changes and human_current_page remains the same when a new tab is opened."""
@@ -239,7 +230,6 @@ class TestTabManagement:
browser_session.human_current_page.url == initial_tab.url == f'{base_url}/page1'
) # human should still be on the very first tab
- @pytest.mark.asyncio
async def test_human_changes_tab(self, browser_session, base_url):
"""Test that human_current_page changes and agent_current_page remains the same when a new tab is opened."""
@@ -261,7 +251,6 @@ class TestTabManagement:
assert current_agent_page.url == initial_tab.url == 'about:blank'
assert browser_session.human_current_page.url == new_human_tab.url == f'{base_url}/page3'
- @pytest.mark.asyncio
async def test_switch_tab(self, browser_session, base_url):
"""Test that switch_tab updates both tab references."""
@@ -297,7 +286,6 @@ class TestTabManagement:
assert current_tab.url == second_tab.url == f'{base_url}/page2' == browser_session.agent_current_page.url
assert browser_session.human_current_page.url == first_tab.url == f'{base_url}/page1'
- @pytest.mark.asyncio
async def test_close_tab(self, browser_session, base_url):
"""Test that closing a tab updates references correctly."""