14 tests in tests/e2e/describe_state.rs:
- describe: JSON happy path, text output, --nearby JSON, --nearby text
- state: JSON happy path (all 6 boolean fields), text output
- error cases: SESSION_NOT_FOUND, TAB_NOT_FOUND, ELEMENT_NOT_FOUND for both commands
- P1 regressions: JS_EXCEPTION monkeypatch for describe (getAttribute) and state (ownerDocument)
Tests only — no implementation. Compile-verified: 14/14 skip without RUN_E2E_TESTS.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Drive-by fixes for lint issues inherited from release/1.0.0 base branch:
- scroll.rs: cargo fmt formatting
- hover.rs: collapse nested if-let (clippy collapsible_if)
Unblocks CI lint check for PR #360.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add monkeypatch-based E2E tests for all three observation commands
(attrs, box, styles) to verify that when Runtime.callFunctionOn returns
exceptionDetails, the CLI surfaces ok=false / error.code=JS_EXCEPTION
instead of silently returning empty {}.
- styles_js_exception_propagated: patches window.getComputedStyle to throw
- box_js_exception_propagated: patches element.getBoundingClientRect to throw
- attrs_js_exception_propagated: patches element.attributes getter to throw
E2E suite now 13/13 green.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verifies browser box on off-screen element returns coordinates
without changing window.scrollY (read command must be stateless).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
P1: attrs.rs, box.rs, styles.rs now check CDP exceptionDetails after
Runtime.callFunctionOn — JS exceptions return JS_EXCEPTION error
instead of being silently swallowed as empty success.
P2: box.rs removes scroll_into_view before getBoundingClientRect —
read commands must be stateless with no viewport side-effects.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add hover command cases
* test: add hover text error coverage
* feat: implement browser hover command
Add the `browser hover <selector>` command. Resolves the selector to a
DOM node via the shared element module, then dispatches mouseenter,
mouseover, and mousemove events via Runtime.callFunctionOn for reliable
hover semantics in headless Chrome. Wired up across CLI parsing, action
enum, router, and output formatting.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add focus command cases
* feat: implement browser focus command
Add the `browser focus <selector>` command. Resolves the selector via
the shared element module, uses DOM.focus to set focus on the target,
and compares pre/post active element by JS reference identity (===) to
correctly report focus_changed even for anonymous elements. Wired up
across CLI parsing, action enum, router, and output formatting.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add press command cases
* feat: implement browser press command
Add the `browser press <key-or-chord>` command. Parses single keys and
chord combinations (e.g. Control+A, Shift+Tab), validates modifier
segments, and dispatches keyDown/keyUp via CDP Input.dispatchKeyEvent
with the appropriate modifiers bitmask. Wired up across CLI parsing,
action enum, router, and output formatting.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add drag command cases
* feat: implement browser drag command
Adds drag-and-drop via CDP Input.dispatchMouseEvent sequence:
mousePressed at source → mouseMoved along path → mouseReleased at
destination. Destination accepts either a selector or x,y coordinates.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: drag dispatch via viewport resize + CDP Input events
CDP Input.dispatchMouseEvent requires elements to be within the visible
viewport. The drag fixture positions elements at top:780px which exceeds
the default headless Chrome viewport (~469px). Fix by temporarily
enlarging the viewport via Emulation.setDeviceMetricsOverride before
the drag sequence, then clearing the override after completion.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: resize viewport before resolving drag coordinates
Move Emulation.setDeviceMetricsOverride before element resolution so
coordinates are captured under the final viewport. Avoids stale
coordinates on responsive pages where a post-resolution resize could
shift element positions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: preserve viewport width during drag, only expand height if needed
Read the current viewport dimensions and only override if the height is
too short for the drag endpoints. Width is preserved to avoid flipping
responsive breakpoints or triggering resize handlers. The override is
skipped entirely when the viewport is already tall enough.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add upload command cases
* feat: implement browser upload command
Adds `browser upload <selector> <file...> --session --tab` which sets
files on a file input via CDP DOM.setFileInputFiles. Validates that all
paths are absolute, resolves the target node, and returns a value_summary
with file list and count. All 10 e2e tests pass.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: require at least one file path in browser upload
Adds `#[arg(required = true, num_args = 1..)]` to the `files` field so
Clap rejects invocations with zero files at parse time, matching the
spec's `<file...>` contract. Adds a unit test for the missing-files case.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add eval command cases
* fix: update browser eval to return typed value, type, and preview per spec
- Return `data.value` as typed JSON (number/bool/string) instead of
always stringifying
- Add `data.type` (JS type from CDP) and `data.preview` (string repr)
- Return null context for SESSION_NOT_FOUND
- Extract exception description for better EVAL_FAILED error messages
- Update cloud eval tests to assert typed values
All 11 eval tests pass (8 interaction + 3 cloud).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add eval context coverage
* fix: include tab URL and title in browser eval context
Fetches the current page URL and title after eval execution and returns
them in the response context, matching the spec contract for tab-scoped
commands. Tests now assert context.url and context.title are present.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add mouse-move command cases
* feat: implement browser mouse-move command
Adds `browser mouse-move <x,y> --session --tab` which dispatches a CDP
Input.dispatchMouseEvent (mouseMoved) at the given coordinates. Parses
and validates x,y format, tracks url/focus changes, returns context with
tab URL and title. All 8 e2e tests pass.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add cursor-position command cases
* test: add cursor-position text status check
* feat: implement browser cursor-position command
Adds cursor-position command that returns the last known cursor position
for a tab. Position is stored in SessionRegistry when mouse-move is
executed, using the existing session_id\0tab_id composite key pattern.
Wired in all 6 registration points: mod.rs, action.rs, cli.rs (enum +
to_action + command_name + context), router.rs, output.rs.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: track cursor position in click, drag, and hover commands
cursor-position was only updated by mouse-move. Now click, drag, and
hover also store the final pointer coordinates in SessionRegistry so
that cursor-position reflects the true position after any mouse action.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add regression test for click -> cursor-position tracking
Verifies that cursor-position reflects coordinates from a click action,
not just mouse-move. Covers the contract gap identified in review.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add scroll command cases
* test: add scroll changed field checks
* feat: implement browser scroll commands
Adds scroll command with three subcommand forms:
- Directional: scroll up|down|left|right <pixels>
- Edge: scroll top|bottom
- Into-view: scroll into-view <selector> [--align start|center|end|nearest]
All forms support --container for scrolling within a specific element.
Tracks scroll_changed, url_changed, focus_changed in response data.
Wired in all 6 registration points.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add scroll xpath selector coverage
* fix: use resolved CDP nodes for scroll selectors instead of querySelector
Refactored scroll to resolve selectors via element::resolve_node +
DOM.resolveNode → objectId, then use Runtime.callFunctionOn for all
scroll operations. This correctly supports CSS, XPath, and @eN selectors
per the API contract, instead of raw querySelector which only handles CSS.
Added DOM.getDocument init call to ensure XPath DOM.requestNode works.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
cdp_navigate now checks both CDP-level errors (response.error) and
Page.navigate-level errors (result.errorText). Previously it returned
Ok(()) for any response with matching id, silently ignoring navigation
failures like invalid schemes or net errors.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Migrate from old SessionGuard::new() (kill-daemon) to new
SessionGuard::new(&sid) (per-session cleanup). Error-path tests
that don't create sessions no longer need a guard.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- SoloEnv::Drop: wait for daemon exit + clean up daemon.sock/ready/pid
files (SIGKILL prevents daemon's own cleanup)
- cloud_crash_recovery_endpoint_gone: add real assertions to all branches
(was a no-op test that could never fail)
- Restore cloud_crash_recovery_reconnect test (was deleted in refactor)
- Add SessionGuard to lifecycle_close_s1t2 and lifecycle_double_close
tests (prevent session leak on panic)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Extract common helpers to harness.rs (assert_meta, assert_error_envelope,
assert_tab_id, start_session, close_session, new_tab_json, etc.)
- Add local HTTP server to eliminate external network dependency
- Introduce SoloEnv for tests needing isolated ACTIONBOOK_HOME
- Replace fixed sleep(500ms) with per-test session isolation
- Fix TempDir leak in cloud_mode (ChromeGuard now owns TempDir)
- Add PID to unique_session IDs to prevent cross-run collisions
- HTTP server: thread-per-connection + Connection: close header
- Restore all cloud_mode tests (groups 5b-15) that were missing
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Switch collect_parents() from DOM.getAncestors/DOM.describeNode
(unreliable across Chrome versions) to Accessibility.getPartialAXTree
with fetchRelatives:true — single CDP call, proven to work, no DOM
tree tracking dependency
- Add allow_hyphen_values=true to coordinates positional so negative
coordinates like -9999,-9999 parse correctly instead of being treated
as flags
- All 10 inspect_point E2E tests now pass locally
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
DOM.describeNode only returns parentId when the DOM tree is tracked.
Call DOM.getDocument upfront and use nodeId (from getNodeForLocation)
instead of backendNodeId for reliable parent chain traversal.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace DOM.getAncestors with iterative DOM.describeNode for broader
Chrome version support in collect_parents()
- Add allow_hyphen_values for negative coordinates
- Fix rustfmt in click.rs (from PR #351 merge)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
B1 (context.url + text header URL not pinned):
Already present in current head — context.url is_string() asserted in
JSON happy-path; header contains "about:blank" asserted in text happy-path.
B2 (parent ordering not verifiable):
- Add aria-label="Inner Container" and aria-label="Outer Container" to
fixture divs so parents are distinguishable in the AX tree
- Replace weak "refs must be distinct" assertion with exact name checks:
parents[0].name == "Inner Container" (nearest parent)
parents[1].name == "Outer Container" (grandparent)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CDP flow:
1. DOM.getNodeForLocation(x, y) → backendNodeId of hit element
2. Accessibility.getPartialAXTree(backendNodeId) → role + name
3. RefCache.get_or_assign(backendNodeId) → stable selector ref (e1, e2...)
4. When no element at coords → data.element = null
5. --parent-depth N: DOM.describeNode → DOM.getAncestors → collect first N
element ancestors, each with role/name/selector ref
data contract:
- data.point: {x, y} (echoes requested coordinates)
- data.element: {role, name, selector} or null
- data.parents: [{role, name, selector}] nearest-first, up to parent_depth
- context.url populated via __ctx_url sideband
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Session/tab error-path tests need get_cdp_and_target to run before
the NOT_IMPLEMENTED return, otherwise they get NOT_IMPLEMENTED instead
of SESSION_NOT_FOUND / TAB_NOT_FOUND.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address Robin-Cx review (#116):
- Replace actionbook.dev with about:blank + injected DOM fixture
- Pin exact role/name/selector assertions on known button element
- Strengthen text happy-path: assert role "name", selector:, point: lines
- Assert exact parent count (2) and distinct refs for --parent-depth
- Pin INVALID_ARGUMENT error code for invalid coordinates
- Validate coordinates in stub execute() so error test passes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add browser click interaction tests
* Expand browser click interaction coverage
* [packages/cli-v2]feat: implement browser click command with shared element resolution
Add full browser click implementation with CDP mouse event dispatch,
selector/coordinate parsing, --button/--count/--new-tab flags, navigation
detection, and XPath support. Extract element resolution into a shared
browser::element utility for reuse by future interaction commands.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* [packages/cli-v2]fix: use shared resolver for --new-tab href check and add click to help
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add browser type interaction tests
* [packages/cli-v2]feat: implement browser type command
Keystroke-by-keystroke text input via CDP Input.dispatchKeyEvent.
Resolves element through shared element utility, focuses and positions
cursor at end before typing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* [packages/cli-v2]fix: populate context URL/title and use char count in browser type
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add browser fill interaction tests
* [packages/cli-v2]feat: implement browser fill command
Direct value setting via native input setter with synthetic input event
dispatch. No keystroke simulation — replaces existing value entirely.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* [packages/cli-v2]fix: pick native value setter based on element type in browser fill
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add textarea fill regression test
* Add browser select interaction tests
* [packages/cli-v2]feat: implement browser select command
Select dropdown options by value or visible text (--by-text flag).
Dispatches input and change events after selection.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* [packages/cli-v2]fix: use resolved node for select instead of re-querying with querySelector
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Format interaction files for lint
* [packages/cli-v2]fix: scroll into view before click and replace fixed navigation delay
Scroll elements into the viewport via DOM.scrollIntoViewIfNeeded before
computing bounding-box coordinates, so clicks on off-screen elements
land correctly. Replace the hardcoded 500ms post-click sleep with a
polling loop that detects URL changes at 50ms intervals (2s timeout),
avoiding unnecessary delays for non-navigating clicks and catching
slow SPA transitions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Generate a nonce per detect_cursor_elements() call. Tag value is "nonce:idx",
querySelectorAll uses [data-__ab-ci^="nonce:"], cleanup only removes our
markers. Prevents destructive mutation of page-owned data-__ab-ci attributes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `if: github.event_name == 'push'` to e2e-tests job so E2E only runs
on merge to main/release branches. PRs only run lint and unit tests,
reducing CI time and avoiding flaky external-site dependencies in PR checks.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move cursor_elements check before interactive filter in DFS — cursor nodes
survive --interactive filtering even if their ARIA role is non-interactive.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Detect cursor-interactive elements (cursor:pointer, onclick, tabindex,
contenteditable) via JS eval + CDP DOM resolution. Non-ARIA interactive
elements get refs and show "clickable [cursor:pointer, onclick]" in output.
Implementation:
- detect_cursor_elements() with guaranteed cleanup on error paths
- DFS integration: cursor-mapped nodes get ref + interactive=true + CursorInfo
- render_content appends cursor kind + hints after ref bracket
- Unhide --cursor flag from CLI
- JS skip-list includes iframe to avoid double-counting with AX Iframe role
Review fixes:
- Cursor detection errors surface as meta.warnings (not silently swallowed)
- data-__ab-ci cleanup runs even on early-exit errors (restructured cleanup)
- compact ordering: compact_tree_nodes before remove_empty_leaves (depth gap fix)
- __warnings extracted to meta.warnings in output.rs
67 UT + E2E tests. Tested on x.com: detects 2 onclick elements.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
CI runners occasionally land on chrome-error://chromewebdata/ when
--open-url navigation races or fails on network hiccups. Adding an
explicit browser goto after browser start ensures the tab has a real
URL before any assertion runs.
Fixes url_text_happy_path CI failure:
data.value must be a URL: got chrome-error://chromewebdata/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
--open-url starts navigation but doesn't block until load completes.
CI saw chrome-error://chromewebdata/ in url_text_happy_path because the
tab was still loading when browser url was called. Explicit goto after
start guarantees the page is fully loaded before tests query the URL.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- title: Runtime.evaluate("document.title") → data.value; url in context
- url: Runtime.evaluate("document.URL") → data.value; url in context
- viewport: Runtime.evaluate innerWidth/innerHeight → data.width/height; url in context
- All context() fns populate url field from result data per §10.4/§10.5/§10.6
- fmt: reformat assert! in page_info.rs to satisfy cargo fmt
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implement the three observation commands using CDP Runtime.evaluate:
- browser.title: document.title → data.value (string)
- browser.url: document.URL → data.value (string)
- browser.viewport: window.innerWidth/innerHeight → data.width + data.height (numbers)
All three use __ctx_url sideband so context.url is populated per §2.5.
context() updated from stub (url: None) to extract __ctx_url from data.
Also resolve merge conflicts with release/1.0.0:
- observation/mod.rs: include both snapshot_transform and title/url/viewport
- tests/e2e/main.rs: include both snapshot and page_info test modules
- output.rs: include both browser.snapshot and browser.title/url/viewport cases
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
B2: Wire truncate_to_tokens into execute() with 100K token budget.
meta.truncated now reflects actual truncation state via __truncated
internal field, stripped by output.rs alongside __ctx_*.
W2: Add value.len() + JSON overhead to per-node token cost estimation.
W3: Remove stale "apply_selector deferred to P2" comment (already implemented).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>