Commit Graph

3 Commits

Author SHA1 Message Date
asensagent e00c48fd28 feat: implement all interaction commands for CLI v1.0.0 (#361)
* 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>
2026-03-29 15:13:54 +08:00
mcfn.feng 8f5ba34f73 [packages/cli-v2]fix: adapt snapshot/interaction/page_info e2e tests to new SessionGuard API
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>
2026-03-29 11:45:39 +08:00
Adcent 24c05c128c [codex] Implement browser interaction commands (#351)
* 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>
2026-03-29 08:36:54 +08:00