feat(core): swipe along a path relative to a node with locator.swipe (ENG-1488)

Draft
SA
4d ago
+301-84

What

locator.swipe() takes a path, { from, to, duration? }, with both points relative to the node:

await screen.getByRole('region', 'Photos').swipe({
  from: { x: '90%', y: '50%' },
  to: { x: '10%', y: '50%' },
  duration: 300,
});
  • A pixel coordinate is an offset from the node's top-left corner, the same corner as tap({ position }). A percentage is a share of the box boundingBox() reports, rounded to a pixel inside it.
  • The swipe is a pointer drag on the web and a touch swipe on a device. The direction form doesn't change.
ThrowsWhen
INVALID_ARGUMENTA mix of the two shapes, an unknown option, a duration that isn't a whole number from 16 through 10000 ms, a negative or non-finite coordinate, or a string that isn't a percentage from '0%' through '100%'
UNSUPPORTED_CAPABILITYAn engine that doesn't list swipeTo in its pointer actions
ACTION_FAILEDA node the browser engine can't scroll into view, or a gesture the engine rejects
LOCATOR_NOT_FOUNDA node that resolves but doesn't get a visible box with non-zero width and height in time

Why

A direction swipe on the web is a wheel event, so a pager built on pointer events doesn't move. screen.swipe({ from, to }) drags, but uses screen coordinates, so tests had to read the node's box and add its offset to each point.

How it works

  1. A path on a locator goes to performWithin instead of perform (packages/core/src/locator/screen.ts:598). swipePath validates the points and the duration and builds the swipeTo action for locator.swipe and screen.swipe. Only a locator takes timeout (packages/core/src/locator/screen.ts:770).
  2. performWithin scrolls the node into view when the engine lists scrollIntoView, then waits for a visible box, as for tap({ position }) (packages/core/src/locator/engine.ts:601). For a swipe, it also waits for non-zero width and height, since every percentage on an empty box lands on one line.
  3. resolveBoxPoint turns both points into viewport points (packages/core/src/internal/geometry.ts:101). A pixel is added to the node's origin, the corner tap({ position }) uses. A percentage goes through resolveCoordinate on rect, the box boundingBox() reports, and is rounded once to a whole pixel inside it (packages/core/src/internal/geometry.ts:89). So '0%' and '100%' stay inside a box that starts between two pixels.
  4. dispatchAt sends the engine one swipeTo through its performAt (packages/core/src/locator/engine.ts:636). The web and mobile engines already declare swipeTo for screen.swipe, so neither engine changes.

Percentages use the box boundingBox() returns. In a frame, that box is clipped to the frame, and the web engine doesn't keep the node's full size. Keeping it would take a new SemanticNode field across the engine protocol. In the top-level document, the box can extend past the viewport.

When the app window's position on screen isn't known (such as a windowed iPad app), a direction swipe fails with ACTION_FAILED, while a path swipe still runs from the offset box. The reference page documents this. To refuse it, the harness would need a contract change so the engine knows the points came from a box.

Issue

Part of ENG-1434.

Verified

Ran it locally: yes

Web, testbed on Chromium. The pad reports where a swipe started and ended, relative to its own corner:

$ e2e run tests/pointer.e2e.ts
 ✓ |web| tests/pointer.e2e.ts > locator.swipe({ from, to }) takes points on the node box, in pixels or percentages
      Tests  9 passed (9)

{ from: { x: 10, y: 20 }, to: { x: '75%', y: '10%' }, duration: 200 } on the 320 × 200 pad reads swiped from 10,20 to 240,20. In Firefox 159 (web({ browser: 'firefox' })), the same file passes 8 of 9, and the new test reads the same swiped from 10,20 to 240,20. raw mouse input drags along the pad fails with swiped from 10,19 to 150,19 instead of 10,20 to 150,20. It fails the same way in Firefox on main at 634d0604, before the rebase, and it doesn't call locator.swipe.

Devices: an iOS 27.2 simulator (iPhone 18 Pro) and an API 36 emulator (Pixel 7, google_apis arm64), each created for this run, with the Release benchmark app built the way mobile.yml builds it. The mobile benchmark's pad test, a locator swipe follows a path relative to the node, swipes the pad from '80%' to '20%' and checks the reported start and end against the pad's width:

iOS      4 runs, 4 passed
Android  4 runs, 4 passed
  • The start has to land within 2 points of '80%' of the pad's width, on its middle row (40 of 80 points).
  • The end has to land within 25 points of '20%', since a fling's reported end can be up to 24 points off from to.
  • The pad's width in points comes from its box, scaled by its 80-point height, so one check works on both platforms.

On iOS, pointer verbs land at the point asked for (pixel taps and a pixel screen.swipe on the pad) passed in the same 4 runs. The full mobile suites weren't run on this head. The pad tests above were.

pnpm bench:ab --suite testbed -- tests/pointer.e2e.ts:

bench-ab: c371f78c (merge base with origin/main) vs 40d5b47d

apps/testbed: e2e run --workers 1 tests/pointer.e2e.ts. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 24.22.1, load 9.0.

The suite's tests or config differ between base and head, so each side ran its own. A timing change can be the test change.

Behavior

These tests are left out of the timing rows below.

  • added tests/pointer.e2e.ts › locator.swipe({ from, to }) takes points on the node box, in pixels or percentages (web)

Timings

Every row but the process wall clock covers the 617 tests whose behavior matched.

Metricbase median (IQR)head median (IQR)change (95% CI)verdict
wall (process)2.50 s (2.48 s-2.54 s)2.82 s (2.79 s-2.88 s)+13.3% (+11.2% to +14.6%)slower
suite (sum of attempts)1.77 s (1.75 s-1.79 s)1.77 s (1.75 s-1.78 s)+0.0% (-3.2% to +1.5%)same, under the floor
action (events)1.00 s (999 ms-1.01 s)1.00 s (1.00 s-1.00 s)-0.1% (-2.7% to +1.9%)same, under the floor
step locator.tap803 ms (802 ms-816 ms)803 ms (802 ms-804 ms)-0.1% (-3.0% to +2.1%)same, under the floor
step app.open376 ms (367 ms-384 ms)373 ms (370 ms-376 ms)-0.3% (-3.8% to +2.2%)same, under the floor
step screen.swipe113 ms (111 ms-114 ms)113 ms (113 ms-115 ms)+0.5% (-6.8% to +6.9%)same, under the floor
step locator.click47 ms (47 ms-48 ms)46 ms (45 ms-47 ms)-3.2% (-7.3% to +1.1%)same, under the floor
step locator.fill24 ms (22 ms-25 ms)23 ms (23 ms-23 ms)+2.2% (-10.0% to +9.6%)same, under the floor
step screen.tapAt23 ms (23 ms-23 ms)23 ms (22 ms-23 ms)0.0% (-6.4% to +6.6%)same
step browser.mouse.move22 ms (21 ms-22 ms)21 ms (19 ms-21 ms)-4.9% (-22.2% to 0.0%)same, under the floor
step expect.toHaveText20 ms (19 ms-20 ms)19 ms (18 ms-20 ms)-0.1% (-12.4% to +8.5%)same, under the floor
step screen.doubleTapAt7 ms (6 ms-7 ms)8 ms (6 ms-8 ms)+6.9% (-7.4% to +24.7%)same, under the floor
step browser.evaluate3 ms (2 ms-3 ms)3 ms (2 ms-3 ms)0.0% (-18.4% to +22.5%)same
step browser.mouse.down1 ms (0 ms-1 ms)0 ms (0 ms-1 ms)0.0% (0.0% to 0.0%)same
step browser.mouse.up1 ms (1 ms-1 ms)1 ms (0 ms-1 ms)0.0% (0.0% to 0.0%)same
step expect.toHaveValue1 ms (1 ms-2 ms)1 ms (1 ms-1 ms)0.0% (-29.3% to 0.0%)same

Counters

Counterbasehead
attempts89
events engine1214
events poll910
steps3437
tests passed89
Tests outside the threshold: 0 of 617

With 617 tests compared at 95%, about 30.9 could land outside by chance.

The wall-clock measurement includes the added test. None of the compared steps were marked slower.

Docs pages: no before and after screenshots. The docs site isn't in this repository, so it can't be rendered locally. pnpm docs:check compiles every changed page.

The video below is the Chromium run of the locator.swipe test.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

https://github.com/user-attachments/assets/b7ff60ea-1f1a-471d-9fc5-b8cc036ede65