browser-use--browser-harness
c390388beb
- Move package to src/browser_harness/ and domain-skills/interaction-skills to agent-workspace/ - Fix all browser-harness <<'PY' heredoc examples in SKILL.md and run.py HELP string to use the correct -c '...' flag format (heredoc was never supported by the CLI) - Update SKILL.md path references from domain-skills/ to agent-workspace/domain-skills/ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
37 行
1.2 KiB
Python
37 行
1.2 KiB
Python
from unittest.mock import patch
|
|
|
|
from browser_harness import helpers
|
|
|
|
|
|
def _capture_cdp():
|
|
captured = []
|
|
def fake_cdp(method, **kwargs):
|
|
captured.append((method, kwargs))
|
|
return {"result": {"value": None}}
|
|
return fake_cdp, captured
|
|
|
|
|
|
def _evaluated_expression(captured):
|
|
return next(kw["expression"] for m, kw in captured if m == "Runtime.evaluate")
|
|
|
|
|
|
def test_simple_expression_passes_through():
|
|
fake_cdp, captured = _capture_cdp()
|
|
with patch("browser_harness.helpers.cdp", side_effect=fake_cdp):
|
|
helpers.js("document.title")
|
|
assert _evaluated_expression(captured) == "document.title"
|
|
|
|
|
|
def test_return_statement_gets_wrapped():
|
|
fake_cdp, captured = _capture_cdp()
|
|
with patch("browser_harness.helpers.cdp", side_effect=fake_cdp):
|
|
helpers.js("const x = 1; return x")
|
|
assert _evaluated_expression(captured) == "(function(){const x = 1; return x})()"
|
|
|
|
|
|
def test_iife_with_internal_return_is_not_double_wrapped():
|
|
fake_cdp, captured = _capture_cdp()
|
|
with patch("browser_harness.helpers.cdp", side_effect=fake_cdp):
|
|
helpers.js("(function(){ return document.title; })()")
|
|
assert _evaluated_expression(captured) == "(function(){ return document.title; })()"
|