Skip to content

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

Cloud browser

Magnus Müller17db15320d37
diff --git a/tests/ci/test_browser_session_element_cache.py b/tests/ci/test_browser_session_element_cache.py
index bed8068c3..20f0dbe9a 100644
--- a/tests/ci/test_browser_session_element_cache.py
+++ b/tests/ci/test_browser_session_element_cache.py
@@ -3,7 +3,6 @@ Systematic debugging of the selector map issue.
Test each assumption step by step to isolate the problem.
"""
-import asyncio
import pytest
diff --git a/tests/ci/test_cloud_browser.py b/tests/ci/test_cloud_browser.py
index e6110ba7c..f0fc76672 100644
--- a/tests/ci/test_cloud_browser.py
+++ b/tests/ci/test_cloud_browser.py
@@ -85,22 +85,18 @@ class TestCloudBrowserClient:
assert 'X-Browser-Use-API-Key' in call_args.kwargs['headers']
assert call_args.kwargs['headers']['X-Browser-Use-API-Key'] == 'test-token'
- async def test_create_browser_auth_error(self, temp_config_dir):
+ async def test_create_browser_auth_error(self, temp_config_dir, monkeypatch):
"""Test cloud browser creation with auth error."""
- # Don't create auth config - should trigger auth error
+ # Clear environment variable and don't create auth config - should trigger auth error
+ monkeypatch.delenv('BROWSER_USE_API_KEY', raising=False)
- with patch('httpx.AsyncClient') as mock_client_class:
- mock_client = AsyncMock()
- mock_client_class.return_value = mock_client
+ client = CloudBrowserClient()
- client = CloudBrowserClient()
- client.client = mock_client
-
- with pytest.raises(CloudBrowserAuthError) as exc_info:
- await client.create_browser()
+ with pytest.raises(CloudBrowserAuthError) as exc_info:
+ await client.create_browser()
- assert 'BROWSER_USE_API_KEY environment variable' in str(exc_info.value)
+ assert 'BROWSER_USE_API_KEY environment variable' in str(exc_info.value)
async def test_create_browser_http_401(self, mock_auth_config, monkeypatch):
"""Test cloud browser creation with HTTP 401 response."""
@@ -301,25 +297,24 @@ async def test_get_cloud_browser_cdp_url_function(mock_auth_config, monkeypatch)
assert cdp_url == 'wss://test.proxy.daytona.works'
-async def test_cloud_browser_auth_error_no_fallback(temp_config_dir):
+async def test_cloud_browser_auth_error_no_fallback(temp_config_dir, monkeypatch):
"""Test that cloud browser throws error when auth fails (no fallback)."""
+ # Clear environment variable and don't create auth config to trigger auth error
+ monkeypatch.delenv('BROWSER_USE_API_KEY', raising=False)
+
# Don't create auth config to trigger auth error
profile = BrowserProfile(use_cloud=True)
- # Test that cloud browser client raises error without fallback
- with patch('browser_use.browser.cloud.get_cloud_browser_cdp_url') as mock_cloud_cdp:
- mock_cloud_cdp.side_effect = CloudBrowserAuthError('No auth token')
+ # Verify that the cloud browser client raises the expected error
+ with pytest.raises(CloudBrowserAuthError) as exc_info:
+ await get_cloud_browser_cdp_url()
- # Verify that the cloud browser client raises the expected error
- with pytest.raises(CloudBrowserAuthError) as exc_info:
- await get_cloud_browser_cdp_url()
-
- assert 'BROWSER_USE_API_KEY environment variable' in str(exc_info.value)
+ assert 'BROWSER_USE_API_KEY environment variable' in str(exc_info.value)
- # Verify profile state unchanged (no fallback)
- assert profile.use_cloud is True
- assert profile.is_local is False
+ # Verify profile state unchanged (no fallback)
+ assert profile.use_cloud is True
+ assert profile.is_local is False
async def test_stop_cloud_browser_session_function(mock_auth_config, monkeypatch):