Skip to content

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

fix more tests

mertunsall6ab1093627ed
diff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompt.md
index d159d2500..37461b79c 100644
--- a/browser_use/agent/system_prompt.md
+++ b/browser_use/agent/system_prompt.md
@@ -74,7 +74,7 @@ Bounding box labels correspond to element indexes - analyze the image to make su
Strictly follow these rules while using the browser and navigating the web:
- Only interact with elements that have a numeric [index] assigned.
- Only use indexes that are explicitly provided.
-- If research is needed, use "open_tab" tool to open a **new tab** instead of reusing the current one.
+- If research is needed, open a **new tab** instead of reusing the current one.
- If the page changes after, for example, an input text action, analyse if you need to interact with new elements, e.g. selecting the right option from the list.
- By default, only elements in the visible viewport are listed. Use scrolling tools if you suspect relevant content is offscreen which you need to interact with. Scroll ONLY if there are more pixels below or above the page. The extract content action gets the full loaded page content.
- If a captcha appears, attempt solving it if possible. If not, use fallback strategies (e.g., alternative site, backtrack).
diff --git a/browser_use/agent/system_prompt_no_thinking.md b/browser_use/agent/system_prompt_no_thinking.md
index 969c94eb0..95f4fc2c4 100644
--- a/browser_use/agent/system_prompt_no_thinking.md
+++ b/browser_use/agent/system_prompt_no_thinking.md
@@ -74,7 +74,7 @@ Bounding box labels correspond to element indexes - analyze the image to make su
Strictly follow these rules while using the browser and navigating the web:
- Only interact with elements that have a numeric [index] assigned.
- Only use indexes that are explicitly provided.
-- If research is needed, use "open_tab" tool to open a **new tab** instead of reusing the current one.
+- If research is needed, open a **new tab** instead of reusing the current one.
- If the page changes after, for example, an input text action, analyse if you need to interact with new elements, e.g. selecting the right option from the list.
- By default, only elements in the visible viewport are listed. Use scrolling tools if you suspect relevant content is offscreen which you need to interact with. Scroll ONLY if there are more pixels below or above the page. The extract content action gets the full loaded page content.
- If a captcha appears, attempt solving it if possible. If not, use fallback strategies (e.g., alternative site, backtrack).
diff --git a/docs/customize/agent-settings.mdx b/docs/customize/agent-settings.mdx
index 7be0eb7de..b7d50b97a 100644
--- a/docs/customize/agent-settings.mdx
+++ b/docs/customize/agent-settings.mdx
@@ -161,8 +161,8 @@ Specify the action as a dictionary where the key is the action name and the valu
```python
initial_actions = [
- {'open_tab': {'url': 'https://www.google.com'}},
- {'open_tab': {'url': 'https://en.wikipedia.org/wiki/Randomness'}},
+ {'go_to_url': {'url': 'https://www.google.com', 'new_tab': true}},
+ {'go_to_url': {'url': 'https://en.wikipedia.org/wiki/Randomness', 'new_tab': true}},
{'scroll_down': {'amount': 1000}},
]
agent = Agent(
diff --git a/docs/customize/custom-functions.mdx b/docs/customize/custom-functions.mdx
index f4d59bb5f..74ffd4d90 100644
--- a/docs/customize/custom-functions.mdx
+++ b/docs/customize/custom-functions.mdx
@@ -8,7 +8,7 @@ Custom actions are functions *you* provide, that are added to our [default actio
Action functions can request [arbitrary parameters](#action-parameters-via-pydantic-model) that the LLM has to come up with + a fixed set of [framework-provided arguments](#framework-provided-parameters) for browser APIs / `Agent(context=...)` / etc.
<Note>
- Our default set of actions is already quite powerful, the built-in `Controller` provides basics like `open_tab`, `scroll_down`, `extract_content`, [and more](https://github.com/browser-use/browser-use/blob/main/browser_use/controller/service.py).
+ Our default set of actions is already quite powerful, the built-in `Controller` provides basics like `go_to_url`, `scroll_down`, `extract_content`, [and more](https://github.com/browser-use/browser-use/blob/main/browser_use/controller/service.py).
</Note>
It's easy to add your own actions to implement additional custom behaviors, integrations with other apps, or performance optimizations.
@@ -223,7 +223,7 @@ await agent2.run()
If you want to exclude some registered actions and make them unavailable to the agent, you can do:
```python
-controller = Controller(exclude_actions=['open_tab', 'search_google'])
+controller = Controller(exclude_actions=['search_google'])
agent = Agent(controller=controller, ...)
```
diff --git a/examples/features/initial_actions.py b/examples/features/initial_actions.py
index adc0cfe50..2138bcfc7 100644
--- a/examples/features/initial_actions.py
+++ b/examples/features/initial_actions.py
@@ -14,8 +14,8 @@ from browser_use.llm import ChatOpenAI
llm = ChatOpenAI(model='gpt-4o')
initial_actions = [
- {'open_tab': {'url': 'https://www.google.com'}},
- {'open_tab': {'url': 'https://en.wikipedia.org/wiki/Randomness'}},
+ {'go_to_url': {'url': 'https://www.google.com', 'new_tab': True}},
+ {'go_to_url': {'url': 'https://en.wikipedia.org/wiki/Randomness', 'new_tab': True}},
{'scroll_down': {'amount': 1000}},
]
agent = Agent(
diff --git a/tests/ci/test_agent_multiprocessing.py b/tests/ci/test_agent_multiprocessing.py
index 21f19ae1f..e9ff2b7ec 100644
--- a/tests/ci/test_agent_multiprocessing.py
+++ b/tests/ci/test_agent_multiprocessing.py
@@ -334,8 +334,9 @@ class TestParallelism:
"next_goal": "Create new tab",
"action": [
{
- "open_tab": {
- "url": "https://example.com"
+ "go_to_url": {
+ "url": "https://example.com",
+ "new_tab": true
}
}
]
diff --git a/tests/ci/test_browser_session_start.py b/tests/ci/test_browser_session_start.py
index fca0c5575..f1320a486 100644
--- a/tests/ci/test_browser_session_start.py
+++ b/tests/ci/test_browser_session_start.py
@@ -691,8 +691,9 @@ class TestBrowserSessionReusePatterns:
"next_goal": "Create a new tab to work in",
"action": [
{
- "open_tab": {
- "url": "%s"
+ "go_to_url": {
+ "url": "%s",
+ "new_tab": true
}
}
]
diff --git a/tests/old/test_agent_actions.py b/tests/old/test_agent_actions.py
index 0a38b6989..773a622de 100644
--- a/tests/old/test_agent_actions.py
+++ b/tests/old/test_agent_actions.py
@@ -47,7 +47,7 @@ async def test_ecommerce_interaction(llm, browser_session):
action_sequence = []
for action in history.model_actions():
action_name = list(action.keys())[0]
- if action_name in ['go_to_url', 'open_tab']:
+ if action_name in ['go_to_url']:
action_sequence.append('navigate')
elif action_name == 'input_text':
action_sequence.append('input')
@@ -81,7 +81,7 @@ async def test_error_recovery(llm, browser_session):
actions_names = history.action_names()
actions = history.model_actions()
- assert 'go_to_url' in actions_names or 'open_tab' in actions_names, f'{actions_names} does not contain go_to_url or open_tab'
+ 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'
diff --git a/tests/old/test_core_functionality.py b/tests/old/test_core_functionality.py
index 4368a1910..c9f1851f0 100644
--- a/tests/old/test_core_functionality.py
+++ b/tests/old/test_core_functionality.py
@@ -170,7 +170,6 @@ class TestCoreFunctionality:
history = await agent.run(max_steps=4)
action_names = history.action_names()
assert 'go_to_url' in action_names
- assert 'open_tab' in action_names
assert 'switch_tab' in action_names
# Verify we're back on the first tab with page1
@@ -186,7 +185,7 @@ class TestCoreFunctionality:
)
history = await agent.run(max_steps=2)
action_names = history.action_names()
- assert 'open_tab' in action_names
+ assert 'go_to_url' in action_names
# Verify we have at least two tabs
tabs_info = await browser_session.get_tabs_info()
diff --git a/tests/old/test_excluded_actions.py b/tests/old/test_excluded_actions.py
deleted file mode 100644
index ad43265ea..000000000
--- a/tests/old/test_excluded_actions.py
+++ /dev/null
@@ -1,83 +0,0 @@
-import pytest
-
-from browser_use.agent.service import Agent
-from browser_use.agent.views import AgentHistoryList
-from browser_use.browser import BrowserSession
-from browser_use.controller.service import Controller
-
-# run with:
-# python -m pytest tests/test_excluded_actions.py -v -k "test_only_open_tab_allowed" --capture=no
-
-
-class MockLLM:
- """Mock LLM for testing"""
-
- async def ainvoke(self, prompt):
- class MockResponse:
- content = 'Mocked LLM response'
-
- return MockResponse()
-
-
[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.stop()
-
-
-def llm():
- """Initialize language model for testing"""
- return MockLLM()
-
-
-# pytest tests/test_excluded_actions.py -v -k "test_only_open_tab_allowed" --capture=no
-async def test_only_open_tab_allowed(llm, browser_session):
- """Test that only open_tab action is available while others are excluded"""
-
- # Create list of all default actions except open_tab
- excluded_actions = [
- 'search_google',
- 'go_to_url',
- 'go_back',
- 'click_element',
- 'input_text',
- 'switch_tab',
- 'extract_content',
- 'done',
- 'scroll_down',
- 'scroll_up',
- 'send_keys',
- 'scroll_to_text',
- 'get_dropdown_options',
- 'select_dropdown_option',
- ]
-
- # Initialize controller with excluded actions
- controller = Controller(exclude_actions=excluded_actions)
-
- # Create agent with a task that would normally use other actions
- agent = Agent(
- task="Go to google.com and search for 'python programming'",
- llm=llm,
- browser_session=browser_session,
- controller=controller,
- )
-
- history: AgentHistoryList = await agent.run(max_steps=2)
-
- # Verify that only open_tab was used
- action_names = history.action_names()
-
- # Only open_tab should be in the actions
- assert all(action == 'open_tab' for action in action_names), (
- f'Found unexpected actions: {[a for a in action_names if a != "open_tab"]}'
- )
-
- # open_tab should be used at least once
- assert 'open_tab' in action_names, 'open_tab action was not used'
diff --git a/tests/old/test_wait_for_element.py b/tests/old/test_wait_for_element.py
index 940e946e1..2e8d55e26 100644
--- a/tests/old/test_wait_for_element.py
+++ b/tests/old/test_wait_for_element.py
@@ -30,7 +30,7 @@ async def test_wait_for_element():
"""Test 'Wait for element' action."""
initial_actions = [
- {'open_tab': {'url': 'https://pypi.org/'}},
+ {'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}},
]