Skip to content

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

removed test for drag and drop

Gregor Žuničb247a8d848b6
diff --git a/tests/ci/test_controller.py b/tests/ci/test_controller.py
index 605df59a7..d701ab92a 100644
--- a/tests/ci/test_controller.py
+++ b/tests/ci/test_controller.py
@@ -14,7 +14,6 @@ from browser_use.controller.views import (
ClickElementAction,
CloseTabAction,
DoneAction,
- DragDropAction,
GoToUrlAction,
InputTextAction,
NoParamsAction,
@@ -539,238 +538,6 @@ class TestControllerIntegration:
assert result.is_done is True
assert result.error is None
- 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
- http_server.expect_request('/dragdrop').respond_with_data(
- """
- <!DOCTYPE html>
- <html>
- <head>
- <title>Drag and Drop Test</title>
- <style>
- body { font-family: Arial, sans-serif; padding: 20px; }
- .container { display: flex; }
- .dropzone {
- width: 200px;
- height: 200px;
- border: 2px dashed #ccc;
- margin: 10px;
- padding: 10px;
- transition: background-color 0.3s;
- }
- .draggable {
- width: 80px;
- height: 80px;
- background-color: #3498db;
- color: white;
- text-align: center;
- line-height: 80px;
- cursor: move;
- user-select: none;
- }
- #log {
- margin-top: 20px;
- padding: 10px;
- border: 1px solid #ccc;
- height: 150px;
- overflow-y: auto;
- }
- </style>
- </head>
- <body>
- <h1>Drag and Drop Test</h1>
-
- <div class="container">
- <div id="zone1" class="dropzone">
- Zone 1
- <div id="draggable" class="draggable" draggable="true">Drag me</div>
- </div>
-
- <div id="zone2" class="dropzone">
- Zone 2
- </div>
- </div>
-
- <div id="log">Event log:</div>
-
- <script>
- // Track item position for verification
- function updateStatus() {
- const element = document.getElementById('draggable');
- const parent = element.parentElement;
- document.getElementById('status').textContent =
- `Item is in: ${parent.id}, dropped count: ${dropCount}`;
- }
-
- // Element references
- const draggable = document.getElementById('draggable');
- const dropzones = document.querySelectorAll('.dropzone');
- const log = document.getElementById('log');
-
- // Counters for verification
- let dragStartCount = 0;
- let dropCount = 0;
-
- // Log events
- function logEvent(event) {
- const info = event.type;
- log.textContent += info + ';';
- }
-
- // Add status display
- const statusDiv = document.createElement('div');
- statusDiv.id = 'status';
- document.body.appendChild(statusDiv);
-
- // Drag events for the draggable element
- draggable.addEventListener('dragstart', (e) => {
- dragStartCount++;
- logEvent(e);
- // Required for Firefox
- e.dataTransfer.setData('text/plain', '');
- e.target.style.opacity = '0.5';
- });
-
- draggable.addEventListener('dragend', (e) => {
- logEvent(e);
- e.target.style.opacity = '1';
- updateStatus();
- });
-
- // Events for the dropzones
- dropzones.forEach(zone => {
- zone.addEventListener('dragover', (e) => {
- e.preventDefault(); // Allow drop
- logEvent(e);
- zone.style.backgroundColor = '#f0f0f0';
- });
-
- zone.addEventListener('dragleave', (e) => {
- logEvent(e);
- zone.style.backgroundColor = '';
- });
-
- zone.addEventListener('drop', (e) => {
- e.preventDefault();
- logEvent(e);
- zone.style.backgroundColor = '';
-
- // Only append if it's our draggable element
- if (e.dataTransfer.types.includes('text/plain')) {
- dropCount++;
- zone.appendChild(draggable);
- }
- });
- });
-
- // Mouse events
- draggable.addEventListener('mousedown', (e) => logEvent(e));
- document.addEventListener('mouseup', (e) => logEvent(e));
-
- // Initialize status
- updateStatus();
- </script>
- </body>
- </html>
- """,
- content_type='text/html',
- )
-
- # Step 1: Navigate to the drag and drop test page
- goto_action = {'go_to_url': GoToUrlAction(url=f'{base_url}/dragdrop')}
-
- class GoToUrlActionModel(ActionModel):
- go_to_url: GoToUrlAction | None = None
-
- goto_result = await controller.act(GoToUrlActionModel(**goto_action), browser_session)
-
- # Verify navigation worked
- assert goto_result.error is None, f'Navigation failed: {goto_result.error}'
- assert f'Navigated to {base_url}/dragdrop' in goto_result.extracted_content
-
- # Get page reference
- page = await browser_session.get_current_page()
-
- # Verify we loaded the page correctly
- title = await page.title()
- assert title == 'Drag and Drop Test', f'Page did not load correctly, got title: {title}'
-
- # Step 2: Verify initial state - draggable should be in zone1
- initial_parent = await page.evaluate('() => document.getElementById("draggable").parentElement.id')
- assert initial_parent == 'zone1', f'Element should start in zone1, but found in {initial_parent}'
-
- # Step 3: Get the element positions for drag operation
- element_info = await page.evaluate("""
- () => {
- const draggable = document.getElementById("draggable");
- const zone2 = document.getElementById("zone2");
-
- const draggableRect = draggable.getBoundingClientRect();
- const zone2Rect = zone2.getBoundingClientRect();
-
- return {
- source: {
- x: Math.round(draggableRect.left + draggableRect.width/2),
- y: Math.round(draggableRect.top + draggableRect.height/2)
- },
- target: {
- x: Math.round(zone2Rect.left + zone2Rect.width/2),
- y: Math.round(zone2Rect.top + zone2Rect.height/2)
- }
- };
- }
- """)
-
- print(f'Source element position: {element_info["source"]}')
- print(f'Target position: {element_info["target"]}')
-
- # Step 4: Use the controller's DragDropAction to perform the drag
- drag_action = {
- 'drag_drop': DragDropAction(
- # Use the coordinate-based approach
- element_source=None,
- element_target=None,
- element_source_offset=None,
- element_target_offset=None,
- coord_source_x=element_info['source']['x'],
- coord_source_y=element_info['source']['y'],
- coord_target_x=element_info['target']['x'],
- coord_target_y=element_info['target']['y'],
- steps=10, # More steps for smoother movement
- delay_ms=10, # Small delay for browser to process events
- )
- }
-
- class DragDropActionModel(ActionModel):
- drag_drop: DragDropAction | None = None
-
- # Execute the drag action through the controller
- result = await controller.act(DragDropActionModel(**drag_action), browser_session)
-
- # Step 5: Verify the controller action result
- assert result.error is None, f'Drag operation failed with error: {result.error}'
- assert result.is_done is False
- assert result.extracted_content is not None
- assert '🖱️ Dragged from' in result.extracted_content
-
- # Step 6: Verify the element was moved by checking its new parent
- final_parent = await page.evaluate('() => document.getElementById("draggable").parentElement.id')
-
- # Step 7: Get the event log to see what events were fired
- event_log = await page.evaluate('() => document.getElementById("log").textContent')
- print(f'Event log: {event_log}')
-
- # Check that mousedown and mouseup events were recorded
- assert 'mousedown' in event_log, 'No mousedown event detected'
-
- # Step 8: Verify the status shows the item was dropped
- status_text = await page.evaluate('() => document.getElementById("status").textContent')
-
- drag_succeeded = final_parent == 'zone2'
-
- assert drag_succeeded, "Drag and drop events weren't fired correctly"
-
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