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
Tests simplified
Magnus Müller8fa6efa0c9fb
diff --git a/tests/ci/test_browser_event_ClickElementEvent.py b/tests/ci/test_browser_event_ClickElementEvent.pyindex 4d44337e1..c049ca1df 100644--- a/tests/ci/test_browser_event_ClickElementEvent.py+++ b/tests/ci/test_browser_event_ClickElementEvent.py@@ -9,11 +9,6 @@ from browser_use.agent.views import ActionResultfrom browser_use.browser import BrowserSessionfrom browser_use.browser.profile import BrowserProfilefrom browser_use.tools.service import Tools-from browser_use.tools.views import (- ClickElementAction,- GoToUrlAction,- UploadFileAction,-)@pytest.fixture(scope='session')@@ -115,14 +110,7 @@ class TestClickElementEvent:)# Navigate to the clickable elements test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/clickable', new_tab=False)}-- from browser_use.agent.views import ActionModel-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/clickable', new_tab=False, browser_session=browser_session)# Wait for the page to loadawait asyncio.sleep(0.5) # Give page time to load@@ -130,40 +118,17 @@ class TestClickElementEvent:# Initialize the DOM state to populate the selector mapawait browser_session.get_browser_state_summary()- # Get the selector map- selector_map = await browser_session.get_selector_map()-- # Find a clickable element in the selector map- button_index = None- button_text = None-- for idx, element in selector_map.items():- # Look for the first div with class "clickable"- if element.tag_name.lower() == 'div' and 'clickable' in str(element.attributes.get('class', '')):- button_index = idx- button_text = element.get_all_children_text(max_depth=2).strip()- break+ # Find the clickable button by ID+ button_index = await browser_session.get_index_by_id('button1')# Verify we found a clickable element- assert button_index is not None, (- f'Could not find clickable element in selector map. Available elements: {[f"{idx}: {element.tag_name}" for idx, element in selector_map.items()]}'- )+ assert button_index is not None, 'Could not find button1 element'# Define expected test data- expected_button_text = 'Button 1'expected_result_text = 'Button 1 clicked'- # Verify the button text matches what we expect- assert button_text is not None and expected_button_text in button_text, (- f"Expected button text '{expected_button_text}' not found in '{button_text}'"- )-- # Create a model for the click action- class ClickElementActionModel(ActionModel):- click: ClickElementAction | None = None-# Execute the action with the button index- result = await tools.act(ClickElementActionModel(click=ClickElementAction(index=button_index)), browser_session)+ result = await tools.click(index=button_index, browser_session=browser_session)# Verify the result structureassert isinstance(result, ActionResult), 'Result should be an ActionResult instance'@@ -222,34 +187,19 @@ class TestClickElementEvent:)# Navigate to the page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/inline_offscreen', new_tab=False)}-- from browser_use.agent.views import ActionModel-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/inline_offscreen', new_tab=False, browser_session=browser_session)await asyncio.sleep(0.5)# Get the clickable elementsawait browser_session.get_browser_state_summary()- selector_map = await browser_session.get_selector_map()- # Find the inline element- inline_index = None- for idx, element in selector_map.items():- if 'inline-link' in str(element.attributes.get('class', '')):- inline_index = idx- break+ # Find the inline element by class+ inline_index = await browser_session.get_index_by_class('inline-link')assert inline_index is not None, 'Could not find inline element'# Click the element - should click the visible portion- class ClickActionModel(ActionModel):- click: ClickElementAction | None = None-- result = await tools.act(ClickActionModel(click=ClickElementAction(index=inline_index)), browser_session)+ result = await tools.click(index=inline_index, browser_session=browser_session)assert result.error is None, f'Click failed: {result.error}'@@ -304,34 +254,19 @@ class TestClickElementEvent:)# Navigate to the page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/block_in_inline', new_tab=False)}-- from browser_use.agent.views import ActionModel-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/block_in_inline', new_tab=False, browser_session=browser_session)await asyncio.sleep(0.5)# Get the clickable elementsawait browser_session.get_browser_state_summary()- selector_map = await browser_session.get_selector_map()- # Find the block element inside inline- block_index = None- for idx, element in selector_map.items():- if 'block-inside' in str(element.attributes.get('class', '')):- block_index = idx- break+ # Find the block element by class+ block_index = await browser_session.get_index_by_class('block-inside')assert block_index is not None, 'Could not find block element'# Click the block element- class ClickActionModel(ActionModel):- click: ClickElementAction | None = None-- result = await tools.act(ClickActionModel(click=ClickElementAction(index=block_index)), browser_session)+ result = await tools.click(index=block_index, browser_session=browser_session)assert result.error is None, f'Click failed: {result.error}'@@ -392,34 +327,19 @@ class TestClickElementEvent:)# Navigate to the page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/covered_element', new_tab=False)}-- from browser_use.agent.views import ActionModel-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/covered_element', new_tab=False, browser_session=browser_session)await asyncio.sleep(0.5)# Get the clickable elementsawait browser_session.get_browser_state_summary()- selector_map = await browser_session.get_selector_map()- # Find the target element- target_index = None- for idx, element in selector_map.items():- if 'target' in str(element.attributes.get('class', '')):- target_index = idx- break+ # Find the target element by class+ target_index = await browser_session.get_index_by_class('target')assert target_index is not None, 'Could not find target element'# Click should still work on the visible portion- class ClickActionModel(ActionModel):- click: ClickElementAction | None = None-- result = await tools.act(ClickActionModel(click=ClickElementAction(index=target_index)), browser_session)+ result = await tools.click(index=target_index, browser_session=browser_session)assert result.error is None, f'Click failed: {result.error}'@@ -452,35 +372,19 @@ class TestClickElementEvent:)# Navigate to the page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/file_input', new_tab=False)}-- from browser_use.agent.views import ActionModel-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/file_input', new_tab=False, browser_session=browser_session)await asyncio.sleep(0.5)# Get the clickable elementsawait browser_session.get_browser_state_summary()- selector_map = await browser_session.get_selector_map()- # Find the file input- file_input_index = None- for idx, element in selector_map.items():- if element.tag_name and element.tag_name.lower() == 'input':- if element.attributes and element.attributes.get('type') == 'file':- file_input_index = idx- break+ # Find the file input by ID+ file_input_index = await browser_session.get_index_by_id('fileInput')assert file_input_index is not None, 'Could not find file input element'- # Attempt to click should raise an exception- class ClickActionModel(ActionModel):- click: ClickElementAction | None = None-- result = await tools.act(ClickActionModel(click=ClickElementAction(index=file_input_index)), browser_session)+ # Attempt to click should raise an error+ result = await tools.click(index=file_input_index, browser_session=browser_session)# Should have an error about file inputsassert result.error is not None, 'Expected error for file input click'@@ -513,34 +417,19 @@ class TestClickElementEvent:)# Navigate to the page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/select_dropdown', new_tab=False)}-- from browser_use.agent.views import ActionModel-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/select_dropdown', new_tab=False, browser_session=browser_session)await asyncio.sleep(0.5)# Get the clickable elementsawait browser_session.get_browser_state_summary()- selector_map = await browser_session.get_selector_map()- # Find the select element- select_index = None- for idx, element in selector_map.items():- if element.tag_name and element.tag_name.lower() == 'select':- select_index = idx- break+ # Find the select element by ID+ select_index = await browser_session.get_index_by_id('testSelect')assert select_index is not None, 'Could not find select element'- # Attempt to click should raise an exception- class ClickActionModel(ActionModel):- click: ClickElementAction | None = None-- result = await tools.act(ClickActionModel(click=ClickElementAction(index=select_index)), browser_session)+ # Attempt to click should provide dropdown options+ result = await tools.click(index=select_index, browser_session=browser_session)# Should automatically provide dropdown options instead of an errorassert result.error is None, 'Should not have error - should provide dropdown options automatically'@@ -910,14 +799,7 @@ class TestClickElementEvent:)# Navigate to the file upload test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/fileupload', new_tab=False)}-- from browser_use.agent.views import ActionModel-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/fileupload', new_tab=False, browser_session=browser_session)# Wait for the page to loadawait asyncio.sleep(0.5)@@ -925,22 +807,11 @@ class TestClickElementEvent:# Initialize the DOM state to populate the selector mapawait browser_session.get_browser_state_summary()- # Get the selector map- selector_map = await browser_session.get_selector_map()-- # Find the label element that triggers the file input- label_index = None- for idx, element in selector_map.items():- if element.tag_name.lower() == 'label' and 'upload-label' in str(element.attributes.get('class', '')):- label_index = idx- break+ # Find the label element that triggers the file input by class+ label_index = await browser_session.get_index_by_class('upload-label')assert label_index is not None, 'Could not find file upload label element'- # Create action model for file upload- class UploadFileActionModel(ActionModel):- upload_file: UploadFileAction | None = None-# Create a temporary FileSystem for the testimport tempfile@@ -950,9 +821,10 @@ class TestClickElementEvent:file_system = FileSystem(base_dir=temp_dir)# Upload the file using the label index (should find the associated file input)- result = await tools.act(- UploadFileActionModel(upload_file=UploadFileAction(index=label_index, path=temp_file_path)),- browser_session,+ result = await tools.upload_file(+ index=label_index,+ path=temp_file_path,+ browser_session=browser_session,available_file_paths=[temp_file_path], # Pass the file path as availablefile_system=file_system, # Pass the required file_system parameter)@@ -1034,7 +906,6 @@ class TestClickElementEvent:from browser_use.browser.views import BrowserErrorfrom browser_use.filesystem.file_system import FileSystem- from browser_use.tools.views import UploadFileAction# Create a temporary test file that's NOT in available_file_pathswith tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as temp_file:@@ -1056,13 +927,7 @@ class TestClickElementEvent:)# Navigate to the test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/upload-test', new_tab=False)}- from browser_use.agent.views import ActionModel-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/upload-test', new_tab=False, browser_session=browser_session)await asyncio.sleep(0.5)# Get browser state to populate selector map@@ -1071,21 +936,16 @@ class TestClickElementEvent:event = browser_session.event_bus.dispatch(BrowserStateRequestEvent())state = await event- # Test 1: Try to upload a file that's not in available_file_paths - should fail- class UploadActionModel(ActionModel):- upload_file: UploadFileAction | None = None-- upload_action = UploadActionModel(upload_file=UploadFileAction(index=1, path=test_file_path))-# Create a temporary FileSystem for all testswith tempfile.TemporaryDirectory() as temp_dir:file_system = FileSystem(base_dir=temp_dir)try:# This should fail because the file is not in available_file_paths- result = await tools.act(- upload_action,- browser_session,+ result = await tools.upload_file(+ index=1,+ path=test_file_path,+ browser_session=browser_session,available_file_paths=[], # Empty available_file_pathsfile_system=file_system,)diff --git a/tests/ci/test_browser_event_GetDropdownOptionsEvent.py b/tests/ci/test_browser_event_GetDropdownOptionsEvent.pyindex a761b7a92..a7f1a2262 100644--- a/tests/ci/test_browser_event_GetDropdownOptionsEvent.py+++ b/tests/ci/test_browser_event_GetDropdownOptionsEvent.py@@ -9,12 +9,11 @@ This file consolidates all tests related to dropdown functionality including:import pytestfrom pytest_httpserver import HTTPServer-from browser_use.agent.views import ActionModel, ActionResult+from browser_use.agent.views import ActionResultfrom browser_use.browser import BrowserSessionfrom browser_use.browser.events import GetDropdownOptionsEvent, NavigationCompleteEvent, SelectDropdownOptionEventfrom browser_use.browser.profile import BrowserProfilefrom browser_use.tools.service import Tools-from browser_use.tools.views import GoToUrlAction@pytest.fixture(scope='session')@@ -278,36 +277,18 @@ class TestGetDropdownOptionsEvent:async def test_native_select_dropdown(self, tools, browser_session: BrowserSession, base_url):"""Test get_dropdown_options with native HTML select element."""# Navigate to the native dropdown test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/native-dropdown', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/native-dropdown', new_tab=False, browser_session=browser_session)# Initialize the DOM state to populate the selector mapawait browser_session.get_browser_state_summary()- # Get the selector map and find the select element- selector_map = await browser_session.get_selector_map()- dropdown_index = None- for idx, element in selector_map.items():- if element.tag_name.lower() == 'select' and element.attributes.get('id') == 'test-dropdown':- dropdown_index = idx- break+ # Find the select element by ID+ dropdown_index = await browser_session.get_index_by_id('test-dropdown')- assert dropdown_index is not None, (- f'Could not find select element in selector map. Available elements: {[f"{idx}: {element.tag_name}" for idx, element in selector_map.items()]}'- )+ assert dropdown_index is not None, 'Could not find select element'# Test via tools action- class GetDropdownOptionsModel(ActionModel):- get_dropdown_options: dict[str, int]-- result = await tools.act(- action=GetDropdownOptionsModel(get_dropdown_options={'index': dropdown_index}),- browser_session=browser_session,- )+ result = await tools.dropdown_options(index=dropdown_index, browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -336,43 +317,18 @@ class TestGetDropdownOptionsEvent:async def test_aria_menu_dropdown(self, tools, browser_session: BrowserSession, base_url):"""Test get_dropdown_options with ARIA role='menu' element."""# Navigate to the ARIA menu test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/aria-menu', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/aria-menu', new_tab=False, browser_session=browser_session)# Initialize the DOM stateawait browser_session.get_browser_state_summary()- # Get the selector map and find the ARIA menu- selector_map = await browser_session.get_selector_map()- menu_index = None- for idx, element in selector_map.items():- if (- element.tag_name.lower() == 'ul'- and element.attributes.get('role') == 'menu'- and element.attributes.get('id') == 'pyNavigation1752753375773'- ):- menu_index = idx- break-- assert menu_index is not None, 'Could not find ARIA menu element in selector map. Available elements: [%s]' % (- ', '.join(- '{}: {} role={}'.format(idx, element.tag_name, element.attributes.get('role', 'None'))- for idx, element in selector_map.items()- )- )+ # Find the ARIA menu by ID+ menu_index = await browser_session.get_index_by_id('pyNavigation1752753375773')- # Test via tools action- class GetDropdownOptionsModel(ActionModel):- get_dropdown_options: dict[str, int]+ assert menu_index is not None, 'Could not find ARIA menu element'- result = await tools.act(- action=GetDropdownOptionsModel(get_dropdown_options={'index': menu_index}),- browser_session=browser_session,- )+ # Test via tools action+ result = await tools.dropdown_options(index=menu_index, browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -398,39 +354,18 @@ class TestGetDropdownOptionsEvent:async def test_custom_dropdown(self, tools, browser_session: BrowserSession, base_url):"""Test get_dropdown_options with custom dropdown implementation."""# Navigate to the custom dropdown test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/custom-dropdown', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/custom-dropdown', new_tab=False, browser_session=browser_session)# Initialize the DOM stateawait browser_session.get_browser_state_summary()- # Get the selector map and find the custom dropdown- selector_map = await browser_session.get_selector_map()- dropdown_index = None- for idx, element in selector_map.items():- if element.attributes.get('id') == 'custom-dropdown' and 'dropdown' in element.attributes.get('class', ''):- dropdown_index = idx- break-- assert dropdown_index is not None, 'Could not find custom dropdown element in selector map. Available elements: [%s]' % (- ', '.join(- '{}: {} id={}'.format(idx, element.tag_name, element.attributes.get('id', 'None'))- for idx, element in selector_map.items()- )- )+ # Find the custom dropdown by ID+ dropdown_index = await browser_session.get_index_by_id('custom-dropdown')- # Test via tools action- class GetDropdownOptionsModel(ActionModel):- get_dropdown_options: dict[str, int]+ assert dropdown_index is not None, 'Could not find custom dropdown element'- result = await tools.act(- action=GetDropdownOptionsModel(get_dropdown_options={'index': dropdown_index}),- browser_session=browser_session,- )+ # Test via tools action+ result = await tools.dropdown_options(index=dropdown_index, browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -460,35 +395,19 @@ class TestSelectDropdownOptionEvent:async def test_select_native_dropdown_option(self, tools, browser_session: BrowserSession, base_url):"""Test select_dropdown_option with native HTML select element."""# Navigate to the native dropdown test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/native-dropdown', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/native-dropdown', new_tab=False, browser_session=browser_session)await browser_session.event_bus.expect(NavigationCompleteEvent, timeout=10.0)# Initialize the DOM stateawait browser_session.get_browser_state_summary()- # Get the selector map and find the select element- selector_map = await browser_session.get_selector_map()- dropdown_index = None- for idx, element in selector_map.items():- if element.tag_name.lower() == 'select' and element.attributes.get('id') == 'test-dropdown':- dropdown_index = idx- break+ # Find the select element by ID+ dropdown_index = await browser_session.get_index_by_id('test-dropdown')assert dropdown_index is not None# Test via tools action- class SelectDropdownOptionModel(ActionModel):- select_dropdown_option: dict-- result = await tools.act(- SelectDropdownOptionModel(select_dropdown_option={'index': dropdown_index, 'text': 'Second Option'}),- browser_session,- )+ result = await tools.select_dropdown(index=dropdown_index, text='Second Option', browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -508,39 +427,19 @@ class TestSelectDropdownOptionEvent:async def test_select_aria_menu_option(self, tools, browser_session: BrowserSession, base_url):"""Test select_dropdown_option with ARIA menu."""# Navigate to the ARIA menu test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/aria-menu', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/aria-menu', new_tab=False, browser_session=browser_session)await browser_session.event_bus.expect(NavigationCompleteEvent, timeout=10.0)# Initialize the DOM stateawait browser_session.get_browser_state_summary()- # Get the selector map and find the ARIA menu- selector_map = await browser_session.get_selector_map()- menu_index = None- for idx, element in selector_map.items():- if (- element.tag_name.lower() == 'ul'- and element.attributes.get('role') == 'menu'- and element.attributes.get('id') == 'pyNavigation1752753375773'- ):- menu_index = idx- break+ # Find the ARIA menu by ID+ menu_index = await browser_session.get_index_by_id('pyNavigation1752753375773')assert menu_index is not None# Test via tools action- class SelectDropdownOptionModel(ActionModel):- select_dropdown_option: dict-- result = await tools.act(- SelectDropdownOptionModel(select_dropdown_option={'index': menu_index, 'text': 'Filter'}),- browser_session,- )+ result = await tools.select_dropdown(index=menu_index, text='Filter', browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -560,35 +459,19 @@ class TestSelectDropdownOptionEvent:async def test_select_custom_dropdown_option(self, tools, browser_session: BrowserSession, base_url):"""Test select_dropdown_option with custom dropdown."""# Navigate to the custom dropdown test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/custom-dropdown', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/custom-dropdown', new_tab=False, browser_session=browser_session)await browser_session.event_bus.expect(NavigationCompleteEvent, timeout=10.0)# Initialize the DOM stateawait browser_session.get_browser_state_summary()- # Get the selector map and find the custom dropdown- selector_map = await browser_session.get_selector_map()- dropdown_index = None- for idx, element in selector_map.items():- if element.attributes.get('id') == 'custom-dropdown' and 'dropdown' in element.attributes.get('class', ''):- dropdown_index = idx- break+ # Find the custom dropdown by ID+ dropdown_index = await browser_session.get_index_by_id('custom-dropdown')assert dropdown_index is not None# Test via tools action- class SelectDropdownOptionModel(ActionModel):- select_dropdown_option: dict-- result = await tools.act(- SelectDropdownOptionModel(select_dropdown_option={'index': dropdown_index, 'text': 'Blue'}),- browser_session,- )+ result = await tools.select_dropdown(index=dropdown_index, text='Blue', browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -608,24 +491,14 @@ class TestSelectDropdownOptionEvent:async def test_select_invalid_option_error(self, tools, browser_session: BrowserSession, base_url):"""Test select_dropdown_option with non-existent option text."""# Navigate to the native dropdown test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/native-dropdown', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/native-dropdown', new_tab=False, browser_session=browser_session)await browser_session.event_bus.expect(NavigationCompleteEvent, timeout=10.0)# Initialize the DOM stateawait browser_session.get_browser_state_summary()- # Get the selector map and find the select element- selector_map = await browser_session.get_selector_map()- dropdown_index = None- for idx, element in selector_map.items():- if element.tag_name.lower() == 'select' and element.attributes.get('id') == 'test-dropdown':- dropdown_index = idx- break+ # Find the select element by ID+ dropdown_index = await browser_session.get_index_by_id('test-dropdown')assert dropdown_index is not Nonediff --git a/tests/ci/test_browser_event_GetDropdownOptionsEvent_aria_menus.py b/tests/ci/test_browser_event_GetDropdownOptionsEvent_aria_menus.pyindex c6d5b850c..30d10d9db 100644--- a/tests/ci/test_browser_event_GetDropdownOptionsEvent_aria_menus.py+++ b/tests/ci/test_browser_event_GetDropdownOptionsEvent_aria_menus.py@@ -1,11 +1,10 @@import pytestfrom pytest_httpserver import HTTPServer-from browser_use.agent.views import ActionModel, ActionResult+from browser_use.agent.views import ActionResultfrom browser_use.browser import BrowserSessionfrom browser_use.browser.profile import BrowserProfilefrom browser_use.tools.service import Tools-from browser_use.tools.views import GoToUrlAction@pytest.fixture(scope='session')@@ -152,12 +151,7 @@ class TestARIAMenuDropdown:async def test_get_dropdown_options_with_aria_menu(self, tools, browser_session: BrowserSession, base_url):"""Test that get_dropdown_options can retrieve options from ARIA menus."""# Navigate to the ARIA menu test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/aria-menu', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/aria-menu', new_tab=False, browser_session=browser_session)# Wait for the page to loadfrom browser_use.browser.events import NavigationCompleteEvent@@ -167,39 +161,13 @@ class TestARIAMenuDropdown:# Initialize the DOM state to populate the selector mapawait browser_session.get_browser_state_summary()- # Get the selector map- selector_map = await browser_session.get_selector_map()+ # Find the ARIA menu element by ID+ menu_index = await browser_session.get_index_by_id('pyNavigation1752753375773')- # Find the ARIA menu element in the selector map- menu_index = None- for idx, element in selector_map.items():- # Look for the main UL with role="menu" and id="pyNavigation1752753375773"- if (- element.tag_name.lower() == 'ul'- and element.attributes.get('role') == 'menu'- and element.attributes.get('id') == 'pyNavigation1752753375773'- ):- menu_index = idx- break-- available_elements = [- f'{idx}: {element.tag_name} id={element.attributes.get("id", "None")} role={element.attributes.get("role", "None")}'- for idx, element in selector_map.items()- ]-- assert menu_index is not None, (- f'Could not find ARIA menu element in selector map. Available elements: {available_elements}'- )-- # Create a model for the get_dropdown_options action- class GetDropdownOptionsModel(ActionModel):- get_dropdown_options: dict[str, int]+ assert menu_index is not None, 'Could not find ARIA menu element'# Execute the action with the menu index- result = await tools.act(- action=GetDropdownOptionsModel(get_dropdown_options={'index': menu_index}),- browser_session=browser_session,- )+ result = await tools.dropdown_options(index=menu_index, browser_session=browser_session)# Verify the result structureassert isinstance(result, ActionResult)@@ -219,12 +187,7 @@ class TestARIAMenuDropdown:async def test_select_dropdown_option_with_aria_menu(self, tools, browser_session: BrowserSession, base_url):"""Test that select_dropdown_option can select an option from ARIA menus."""# Navigate to the ARIA menu test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/aria-menu', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/aria-menu', new_tab=False, browser_session=browser_session)# Wait for the page to loadfrom browser_use.browser.events import NavigationCompleteEvent@@ -234,39 +197,13 @@ class TestARIAMenuDropdown:# Initialize the DOM state to populate the selector mapawait browser_session.get_browser_state_summary()- # Get the selector map- selector_map = await browser_session.get_selector_map()-- # Find the ARIA menu element in the selector map- menu_index = None- for idx, element in selector_map.items():- # Look for the main UL with role="menu" and id="pyNavigation1752753375773"- if (- element.tag_name.lower() == 'ul'- and element.attributes.get('role') == 'menu'- and element.attributes.get('id') == 'pyNavigation1752753375773'- ):- menu_index = idx- break+ # Find the ARIA menu element by ID+ menu_index = await browser_session.get_index_by_id('pyNavigation1752753375773')- available_elements = [- f'{idx}: {element.tag_name} id={element.attributes.get("id", "None")} role={element.attributes.get("role", "None")}'- for idx, element in selector_map.items()- ]-- assert menu_index is not None, (- f'Could not find ARIA menu element in selector map. Available elements: {available_elements}'- )-- # Create a model for the select_dropdown_option action- class SelectDropdownOptionModel(ActionModel):- select_dropdown_option: dict+ assert menu_index is not None, 'Could not find ARIA menu element'# Execute the action with the menu index to select "Filter"- result = await tools.act(- SelectDropdownOptionModel(select_dropdown_option={'index': menu_index, 'text': 'Filter'}),- browser_session,- )+ result = await tools.select_dropdown(index=menu_index, text='Filter', browser_session=browser_session)# Verify the result structureassert isinstance(result, ActionResult)@@ -289,12 +226,7 @@ class TestARIAMenuDropdown:async def test_get_dropdown_options_with_nested_aria_menu(self, tools, browser_session: BrowserSession, base_url):"""Test that get_dropdown_options can handle nested ARIA menus (like Sort submenu)."""# Navigate to the ARIA menu test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/aria-menu', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/aria-menu', new_tab=False, browser_session=browser_session)# Wait for the page to loadfrom browser_use.browser.events import NavigationCompleteEvent@@ -332,15 +264,8 @@ class TestARIAMenuDropdown:f'Could not find any ARIA menu element in selector map. Available elements: {[f"{idx}: {element.tag_name}" for idx, element in selector_map.items()]}')- # Create a model for the get_dropdown_options action- class GetDropdownOptionsModel(ActionModel):- get_dropdown_options: dict[str, int]-# Execute the action with the menu index- result = await tools.act(- action=GetDropdownOptionsModel(get_dropdown_options={'index': nested_menu_index}),- browser_session=browser_session,- )+ result = await tools.dropdown_options(index=nested_menu_index, browser_session=browser_session)# Verify the result structureassert isinstance(result, ActionResult)diff --git a/tests/ci/test_browser_event_NavigateToUrlEvent.py b/tests/ci/test_browser_event_NavigateToUrlEvent.pyindex 76a0f0759..de7b45183 100644--- a/tests/ci/test_browser_event_NavigateToUrlEvent.py+++ b/tests/ci/test_browser_event_NavigateToUrlEvent.py@@ -3,11 +3,10 @@ import asyncioimport pytestfrom pytest_httpserver import HTTPServer-from browser_use.agent.views import ActionModel, ActionResult+from browser_use.agent.views import ActionResultfrom browser_use.browser import BrowserSessionfrom browser_use.browser.profile import BrowserProfilefrom browser_use.tools.service import Tools-from browser_use.tools.views import GoToUrlAction@pytest.fixture(scope='session')@@ -64,13 +63,7 @@ class TestNavigateToUrlEvent:async def test_navigate_action(self, tools, browser_session: BrowserSession, base_url):"""Test that GoToUrlAction navigates to the specified URL and test both state summary methods."""# Test successful navigation to a valid page- action_data = {'navigate': GoToUrlAction(url=f'{base_url}/page1', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- action_model = NavigateActionModel(**action_data)- result = await tools.act(action_model, browser_session)+ result = await tools.navigate(url=f'{base_url}/page1', new_tab=False, browser_session=browser_session)# Verify the successful navigation resultassert isinstance(result, ActionResult)@@ -79,17 +72,8 @@ class TestNavigateToUrlEvent:async def test_navigate_network_error(self, tools, browser_session: BrowserSession):"""Test that navigate handles network errors gracefully instead of throwing hard errors."""- # Create action model for navigate with an invalid domain- action_data = {'navigate': GoToUrlAction(url='https://www.nonexistentdndbeyond.com/', new_tab=False)}-- # Create the ActionModel instance- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- action_model = NavigateActionModel(**action_data)-# Execute the action - should return soft error instead of throwing- result = await tools.act(action_model, browser_session)+ result = await tools.navigate(url='https://www.nonexistentdndbeyond.com/', new_tab=False, browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -130,12 +114,7 @@ class TestNavigateToUrlEvent:initial_tab_count = len(initial_tabs)# Navigate to URL in new tab- action_data = {'navigate': GoToUrlAction(url=f'{base_url}/page2', new_tab=True)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- result = await tools.act(NavigateActionModel(**action_data), browser_session)+ result = await tools.navigate(url=f'{base_url}/page2', new_tab=True, browser_session=browser_session)await asyncio.sleep(0.5)# Verify result@@ -155,16 +134,10 @@ class TestNavigateToUrlEvent:async def test_navigate_javascript_url(self, tools, browser_session, base_url):"""Test that javascript: URLs are handled appropriately."""# Navigate to a normal page first- action_data = {'navigate': GoToUrlAction(url=f'{base_url}/page1', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**action_data), browser_session)+ await tools.navigate(url=f'{base_url}/page1', new_tab=False, browser_session=browser_session)# Try to navigate to javascript: URL (should be handled gracefully)- js_action = {'navigate': GoToUrlAction(url='javascript:alert("test")', new_tab=False)}- result = await tools.act(NavigateActionModel(**js_action), browser_session)+ result = await tools.navigate(url='javascript:alert("test")', new_tab=False, browser_session=browser_session)# Should either succeed or fail gracefullyassert isinstance(result, ActionResult)@@ -174,12 +147,7 @@ class TestNavigateToUrlEvent:# Create a simple data URLdata_url = 'data:text/html,<html><head><title>Data URL Test</title></head><body><h1>Data URL Content</h1></body></html>'- action_data = {'navigate': GoToUrlAction(url=data_url, new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- result = await tools.act(NavigateActionModel(**action_data), browser_session)+ result = await tools.navigate(url=data_url, new_tab=False, browser_session=browser_session)# Verify navigationassert isinstance(result, ActionResult)@@ -210,12 +178,9 @@ class TestNavigateToUrlEvent:)# Navigate to page with hash- action_data = {'navigate': GoToUrlAction(url=f'{base_url}/page-with-anchors#section1', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- result = await tools.act(NavigateActionModel(**action_data), browser_session)+ result = await tools.navigate(+ url=f'{base_url}/page-with-anchors#section1', new_tab=False, browser_session=browser_session+ )# Verify navigationassert isinstance(result, ActionResult)@@ -247,12 +212,9 @@ class TestNavigateToUrlEvent:)# Navigate with query parameters- action_data = {'navigate': GoToUrlAction(url=f'{base_url}/search?q=test+query&page=1', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- result = await tools.act(NavigateActionModel(**action_data), browser_session)+ result = await tools.navigate(+ url=f'{base_url}/search?q=test+query&page=1', new_tab=False, browser_session=browser_session+ )# Verify navigationassert isinstance(result, ActionResult)@@ -267,20 +229,13 @@ class TestNavigateToUrlEvent:async def test_navigate_multiple_tabs(self, tools, browser_session, base_url):"""Test navigating in multiple tabs sequentially."""# Navigate to first page in current tab- action1 = {'navigate': GoToUrlAction(url=f'{base_url}/page1', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**action1), browser_session)+ await tools.navigate(url=f'{base_url}/page1', new_tab=False, browser_session=browser_session)# Open second page in new tab- action2 = {'navigate': GoToUrlAction(url=f'{base_url}/page2', new_tab=True)}- await tools.act(NavigateActionModel(**action2), browser_session)+ await tools.navigate(url=f'{base_url}/page2', new_tab=True, browser_session=browser_session)# Open home page in yet another new tab- action3 = {'navigate': GoToUrlAction(url=base_url, new_tab=True)}- await tools.act(NavigateActionModel(**action3), browser_session)+ await tools.navigate(url=base_url, new_tab=True, browser_session=browser_session)# Should have 3 tabs nowtabs = await browser_session.get_tabs()@@ -296,13 +251,8 @@ class TestNavigateToUrlEvent:# Using a private IP that's unlikely to respondtimeout_url = 'http://192.0.2.1:8080/timeout'- action_data = {'navigate': GoToUrlAction(url=timeout_url, new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-# This should complete without hanging indefinitely- result = await tools.act(NavigateActionModel(**action_data), browser_session)+ result = await tools.navigate(url=timeout_url, new_tab=False, browser_session=browser_session)# Should get a result (possibly with error)assert isinstance(result, ActionResult)@@ -317,12 +267,7 @@ class TestNavigateToUrlEvent:)# Navigate to redirect URL- action_data = {'navigate': GoToUrlAction(url=f'{base_url}/redirect', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- result = await tools.act(NavigateActionModel(**action_data), browser_session)+ result = await tools.navigate(url=f'{base_url}/redirect', new_tab=False, browser_session=browser_session)# Verify navigation succeededassert isinstance(result, ActionResult)diff --git a/tests/ci/test_browser_event_ScrollEvent.py b/tests/ci/test_browser_event_ScrollEvent.pyindex 1b1459fe7..2a9bfb2b2 100644--- a/tests/ci/test_browser_event_ScrollEvent.py+++ b/tests/ci/test_browser_event_ScrollEvent.py@@ -3,14 +3,10 @@ import asyncioimport pytestfrom pytest_httpserver import HTTPServer-from browser_use.agent.views import ActionModel, ActionResult+from browser_use.agent.views import ActionResultfrom browser_use.browser import BrowserSessionfrom browser_use.browser.profile import BrowserProfilefrom browser_use.tools.service import Tools-from browser_use.tools.views import (- GoToUrlAction,- ScrollAction,-)@pytest.fixture(scope='session')@@ -83,20 +79,10 @@ class TestScrollActions:"""Test basic scroll action functionality."""# Navigate to scrollable page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/scrollable', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/scrollable', new_tab=False, browser_session=browser_session)# Test 1: Basic page scroll down- scroll_action = {'scroll': ScrollAction(down=True, pages=1.0)}-- class ScrollActionModel(ActionModel):- scroll: ScrollAction | None = None-- result = await tools.act(ScrollActionModel(**scroll_action), browser_session)+ result = await tools.scroll(down=True, pages=1.0, browser_session=browser_session)# Verify scroll down succeededassert isinstance(result, ActionResult)@@ -106,8 +92,7 @@ class TestScrollActions:assert 'px' in result.extracted_content# Test 2: Basic page scroll up- scroll_up_action = {'scroll': ScrollAction(down=False, pages=0.5)}- result = await tools.act(ScrollActionModel(**scroll_up_action), browser_session)+ result = await tools.scroll(down=False, pages=0.5, browser_session=browser_session)assert isinstance(result, ActionResult)assert result.error is None, f'Scroll up failed: {result.error}'@@ -116,23 +101,11 @@ class TestScrollActions:assert '0.5 pages' in result.extracted_content# Test 3: Test with invalid element index (should error)- invalid_scroll_action = {'scroll': ScrollAction(down=True, pages=1.0, index=999)}- result = await tools.act(ScrollActionModel(**invalid_scroll_action), browser_session)+ result = await tools.scroll(down=True, pages=1.0, index=999, browser_session=browser_session)# This should fail with error about element not foundassert isinstance(result, ActionResult)- assert result.error is not None, 'Expected no error for invalid element index'-- # Test 4: Model parameter validation- scroll_with_index = ScrollAction(down=True, pages=1.0, index=5)- assert scroll_with_index.down is True- assert scroll_with_index.pages == 1.0- assert scroll_with_index.index == 5-- scroll_without_index = ScrollAction(down=False, pages=0.25)- assert scroll_without_index.down is False- assert scroll_without_index.pages == 0.25- assert scroll_without_index.index is None+ assert result.error is not None, 'Expected error for invalid element index'async def test_scroll_with_cross_origin_disabled(self, browser_session, base_url):"""Test that scroll works when cross_origin_iframes is disabled."""diff --git a/tests/ci/test_tools.py b/tests/ci/test_tools.pyindex 44aef7e69..d6fa85a40 100644--- a/tests/ci/test_tools.py+++ b/tests/ci/test_tools.py@@ -6,17 +6,11 @@ import pytestfrom pydantic import BaseModelfrom pytest_httpserver import HTTPServer-from browser_use.agent.views import ActionModel, ActionResult+from browser_use.agent.views import ActionResultfrom browser_use.browser import BrowserSessionfrom browser_use.browser.profile import BrowserProfilefrom browser_use.filesystem.file_system import FileSystemfrom browser_use.tools.service import Tools-from browser_use.tools.views import (- DoneAction,- GoToUrlAction,- NoParamsAction,- SearchAction,-)@pytest.fixture(scope='session')@@ -125,21 +119,10 @@ class TestToolsIntegration:return ActionResult(extracted_content=f'Custom action executed with: {params.text} on {current_url}')# Navigate to a page first- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/page1', new_tab=False)}+ await tools.navigate(url=f'{base_url}/page1', new_tab=False, browser_session=browser_session)- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)-- # Create the custom action model- custom_action_data = {'custom_action': CustomParams(text='test_value')}-- class CustomActionModel(ActionModel):- custom_action: CustomParams | None = None-- # Execute the custom action- result = await tools.act(CustomActionModel(**custom_action_data), browser_session)+ # Execute the custom action directly+ result = await tools.custom_action(text='test_value', browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -163,17 +146,11 @@ class TestToolsIntegration:schema = wait_action.param_model.model_json_schema()assert schema['properties']['seconds']['default'] == 3- # Create wait action for 1 second - fix to use a dictionary- wait_action = {'wait': {'seconds': 3}} # Corrected format-- class WaitActionModel(ActionModel):- wait: dict | None = None-# Record start timestart_time = time.time()# Execute wait action- result = await tools.act(WaitActionModel(**wait_action), browser_session)+ result = await tools.wait(seconds=3, browser_session=browser_session)# Record end timeend_time = time.time()@@ -187,14 +164,11 @@ class TestToolsIntegration:assert end_time - start_time <= 0.5 # We wait 3-3 seconds for LLM call# longer wait- # Create wait action for 1 second - fix to use a dictionary- wait_action = {'wait': {'seconds': 5}} # Corrected format-# Record start timestart_time = time.time()# Execute wait action- result = await tools.act(WaitActionModel(**wait_action), browser_session)+ result = await tools.wait(seconds=5, browser_session=browser_session)# Record end timeend_time = time.time()@@ -209,20 +183,14 @@ class TestToolsIntegration:async def test_go_back_action(self, tools, browser_session, base_url):"""Test that go_back action navigates to the previous page."""# Navigate to first page- goto_action1 = {'navigate': GoToUrlAction(url=f'{base_url}/page1', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action1), browser_session)+ await tools.navigate(url=f'{base_url}/page1', new_tab=False, browser_session=browser_session)# Store the first page URLfirst_url = await browser_session.get_current_page_url()print(f'First page URL: {first_url}')# Navigate to second page- goto_action2 = {'navigate': GoToUrlAction(url=f'{base_url}/page2', new_tab=False)}- await tools.act(NavigateActionModel(**goto_action2), browser_session)+ await tools.navigate(url=f'{base_url}/page2', new_tab=False, browser_session=browser_session)# Verify we're on the second pagesecond_url = await browser_session.get_current_page_url()@@ -230,12 +198,7 @@ class TestToolsIntegration:assert f'{base_url}/page2' in second_url# Execute go back action- go_back_action = {'go_back': NoParamsAction()}-- class GoBackActionModel(ActionModel):- go_back: NoParamsAction | None = None-- result = await tools.act(GoBackActionModel(**go_back_action), browser_session)+ result = await tools.go_back(browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -259,12 +222,7 @@ class TestToolsIntegration:# Navigate to each page in sequencefor url in urls:- action_data = {'navigate': GoToUrlAction(url=url, new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**action_data), browser_session)+ await tools.navigate(url=url, new_tab=False, browser_session=browser_session)# Verify current pagecurrent_url = await browser_session.get_current_page_url()@@ -272,12 +230,7 @@ class TestToolsIntegration:# Go back twice and verify each stepfor expected_url in reversed(urls[:-1]):- go_back_action = {'go_back': NoParamsAction()}-- class GoBackActionModel(ActionModel):- go_back: NoParamsAction | None = None-- await tools.act(GoBackActionModel(**go_back_action), browser_session)+ await tools.go_back(browser_session=browser_session)await asyncio.sleep(1) # Wait for navigation to completecurrent_url = await browser_session.get_current_page_url()@@ -302,12 +255,7 @@ class TestToolsIntegration:await browser_session.get_current_page_url()# Execute search action - it will actually navigate to our search results page- search_action = {'search': SearchAction(query='Python web automation')}-- class SearchActionModel(ActionModel):- search: SearchAction | None = None-- result = await tools.act(SearchActionModel(**search_action), browser_session)+ result = await tools.search(query='Python web automation', browser_session=browser_session)# Verify the resultassert isinstance(result, ActionResult)@@ -325,23 +273,14 @@ class TestToolsIntegration:file_system = FileSystem(temp_dir)# First navigate to a page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/page1', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/page1', new_tab=False, browser_session=browser_session)success_done_message = 'Successfully completed task'- # Create done action with success- done_action = {'done': DoneAction(text=success_done_message, success=True)}-- class DoneActionModel(ActionModel):- done: DoneAction | None = None-# Execute done action with file_system- result = await tools.act(DoneActionModel(**done_action), browser_session, file_system=file_system)+ result = await tools.done(+ text=success_done_message, success=True, browser_session=browser_session, file_system=file_system+ )# Verify the resultassert isinstance(result, ActionResult)@@ -353,11 +292,10 @@ class TestToolsIntegration:failed_done_message = 'Failed to complete task'- # Test with failure case- failed_done_action = {'done': DoneAction(text=failed_done_message, success=False)}-# Execute failed done action with file_system- result = await tools.act(DoneActionModel(**failed_done_action), browser_session, file_system=file_system)+ result = await tools.done(+ text=failed_done_message, success=False, browser_session=browser_session, file_system=file_system+ )# Verify the resultassert isinstance(result, ActionResult)@@ -392,12 +330,7 @@ class TestToolsIntegration:)# Navigate to the dropdown test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/dropdown1', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/dropdown1', new_tab=False, browser_session=browser_session)# Wait for the page to load using CDPcdp_session = browser_session.agent_focus@@ -429,15 +362,8 @@ class TestToolsIntegration:f'Could not find select element in selector map. Available elements: {[f"{idx}: {element.tag_name}" for idx, element in selector_map.items()]}')- # Create a model for the standard dropdown_options action- class DropdownOptionsModel(ActionModel):- dropdown_options: dict[str, int]-# Execute the action with the dropdown index- result = await tools.act(- action=DropdownOptionsModel(dropdown_options={'index': dropdown_index}),- browser_session=browser_session,- )+ result = await tools.dropdown_options(index=dropdown_index, browser_session=browser_session)expected_options = [{'index': 0, 'text': 'Please select', 'value': ''},@@ -516,12 +442,7 @@ class TestToolsIntegration:)# Navigate to the dropdown test page- goto_action = {'navigate': GoToUrlAction(url=f'{base_url}/dropdown2', new_tab=False)}-- class NavigateActionModel(ActionModel):- navigate: GoToUrlAction | None = None-- await tools.act(NavigateActionModel(**goto_action), browser_session)+ await tools.navigate(url=f'{base_url}/dropdown2', new_tab=False, browser_session=browser_session)# Wait for the page to load using CDPcdp_session = browser_session.agent_focus@@ -553,15 +474,8 @@ class TestToolsIntegration:f'Could not find select element in selector map. Available elements: {[f"{idx}: {element.tag_name}" for idx, element in selector_map.items()]}')- # Create a model for the standard select_dropdown action- class SelectDropdownModel(ActionModel):- select_dropdown: dict-# Execute the action with the dropdown index- result = await tools.act(- SelectDropdownModel(select_dropdown={'index': dropdown_index, 'text': 'Second Option'}),- browser_session,- )+ result = await tools.select_dropdown(index=dropdown_index, text='Second Option', browser_session=browser_session)# Verify the result structureassert isinstance(result, ActionResult)