Skip to content

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

fix session reuse hanging in CI

Nick Sweeting797408d8fade
diff --git a/tests/ci/test_browser_session_reuse.py b/tests/ci/test_browser_session_reuse.py
index 5dcf91fd3..a274e9798 100644
--- a/tests/ci/test_browser_session_reuse.py
+++ b/tests/ci/test_browser_session_reuse.py
@@ -85,17 +85,13 @@ class TestBrowserSessionReuse:
assert screenshot_before is not None
assert len(screenshot_before) > 100
- # Force disconnect
- if session.browser_context:
- await session.browser_context.close()
-
- # Force a small delay to ensure disconnection is processed
- await asyncio.sleep(0.1)
+ # Properly kill the session to clean up browser subprocess
+ await session.kill()
- # Reset the connection state to ensure the closed context is cleared
- session._reset_connection_state()
+ # Add a delay to ensure all resources are released
+ await asyncio.sleep(0.5)
- # Manually restart for the next iteration
+ # Start a fresh session for the next iteration
await session.start()
# Take screenshot after regeneration
@@ -106,7 +102,7 @@ class TestBrowserSessionReuse:
)
finally:
- await session.stop()
+ await session.kill()
async def test_browser_session_reuse_with_retry_decorator(self):
"""Test that the retry decorator properly handles browser regeneration"""