feat: swipe by distance and speed, and deprecate momentum (ENG-1492)

Draft
SA
4d ago
+1565-453

What

  • screen.swipe, locator.swipe, and scrollUntilVisible take distance (a share of the container or the locator's node, above 0 up to 1) and speed ('slow' 1500 ms, 'normal' 400 ms, 'fast' 150 ms per drag). On the web, a swipe is a wheel event, so speed doesn't change anything there.
  • On the web and on a device, a screen swipe scrolls the container under the screen's center.
  • On the desktop, a swipe in a direction scrolls by the app's own scroll units, so how far it moves depends on the app, and distance isn't a share of the container.
  • momentum still works, prints a warning once per worker process, and is marked @deprecated, to be removed no earlier than April 1, 2027. Its values scroll different distances: on the web, 'slow' 0.25 (was 0.75) and 'fast' 0.65 (was 1.5), on a device locator 'fast' 0.65 (was 0.8), and on the desktop 'slow' 3 of the app's scroll units (was 2), with 'fast' still 10.
  • On a device, locator.scrollIntoView() is supported. Code that builds an engine swipe action needs distance and durationMs, and the wire still accepts the old shape with momentum alone.
await screen.swipe({ direction: 'down' }); // half the container under the center, 400 ms drags
await screen.swipe({ direction: 'down', distance: 0.8, speed: 'fast' });
await screen.getByTestId('feed').swipe({ direction: 'down', distance: 0.25 }); // a share of the node's box
await screen.scrollUntilVisible(accept); // steps of 0.65 over 800 ms
await screen.swipe({ direction: 'down', momentum: 'fast' }); // deprecated: distance 0.65, speed 'fast'

Why

  • momentum meant a different distance on each engine, and a device screen swipe ignored it.
  • A device screen swipe scrolled the whole screen, even when the content under the center was a smaller scroll pane.

This puts the device drag's start and length where Appium's WebDriverAgent and Maestro put them, and gives the web and a device the same distance.

How it works

flowchart LR
  R[read target] --> V{visible?}
  V -- no --> T{deadline passed?}
  T -- yes --> NF[LOCATOR_NOT_FOUND]
  T -- no --> S["step: 0.65 of the container,<br/>one 800 ms drag"]
  S -- "a device refuses a step<br/>whose drags don't fit" --> NF
  S --> R
  V -- yes --> F{"stepped, and the engine<br/>supports scrollIntoView?"}
  F -- no --> D[done]
  F -- yes --> C["scrollIntoView with center:<br/>web: minimal browser scroll<br/>device: drag toward the middle<br/>when far out, toward hidden content"] --> D
  1. swipeAction turns a test's options into the engine's SwipeAction and refuses an unknown direction (packages/core/src/internal/swipe.ts:42). Setting distance or speed alongside momentum overrides the momentum defaults. Using momentum prints a deprecation warning once per process. 'fast' is SCROLL_STEP.distance, the longest single drag, so it stays one drag on a device (packages/core/src/internal/swipe.ts:25).
  2. The contract's SwipeAction requires distance and durationMs and keeps momentum as a deprecated optional field (packages/core/src/engine/contract.ts:388). Core sends the test's momentum, or 'slow' on its own scroll steps as before (STEP_MOMENTUM, packages/core/src/internal/swipe.ts:16), so an engine built on the old contract keeps working. The protocol server fills in a swipe from an older client that sends momentum alone, for perform and performAt (upgradeSwipe, packages/core/src/internal/swipe.ts:83, called from packages/core/src/engine/protocol/protocol.ts:215). ENGINE_SPI_VERSION stays 1, since bumping it re-keys every committed recording.
  3. scrollUntilVisible steps until the deadline passes, as on main (packages/core/src/locator/screen.ts:324). When a device refuses a step because its drags can't finish before the deadline (OPERATION_TIMEOUT, or ACTION_MAY_HAVE_COMMITTED after the first drag of a split step), the scroll fails with LOCATOR_NOT_FOUND, on the screen and on a locator alike (packages/core/src/locator/screen.ts:341). After at least one step, it calls scrollIntoView with center: true, and a drag that no longer fits doesn't fail a scroll that found its node (packages/core/src/locator/screen.ts:315). On the web, center is the browser's minimal scroll within the operation's timeout, with no wait for the node to stop moving (packages/web/src/actions.ts:355).
  4. The agent's scroll is a default swipe (packages/core/src/agent/action-dispatcher.ts:553), and each page of scroll_to({ text }) is one SCROLL_STEP (packages/core/src/agent/action-dispatcher.ts:690). scroll_to by node id calls scrollIntoView. A text search that finds its target after paging also passes center: true (packages/core/src/agent/action-dispatcher.ts:626).
  5. On a device, swipeDrags turns a distance into agent-device pan drags (packages/mobile/src/support.ts:196). Each drag starts 25% in from the edge the content comes from, and one drag moves at most SCROLL_STEP.distance. A longer distance is split into equal drags. pan throws OPERATION_TIMEOUT unsent if the drags won't fit. Once a drag goes out, it marks the last capture stale, and a later drag that runs out of time throws ACTION_MAY_HAVE_COMMITTED (packages/mobile/src/surface.ts:1499, packages/mobile/src/support.ts:91).
  6. A device screen swipe reads the screen again when an action came after the last read, then measures the viewport with viewportFor, so a rotated or resized screen is swiped across its new size (packages/mobile/src/surface.ts:1603). It takes the smallest visible scroll-area, list, collection, or table node with an area under the screen's center (packages/mobile/src/nodes.ts:862), else the whole screen. A device locator.swipe drags across the node's own box (packages/mobile/src/surface.ts:1695), since every Android screen sits in a full-screen ScrollView.
  7. On a device, scrollIntoView drags nodes cut off at the top or bottom edge toward the middle, splitting long moves (centringDrags, packages/mobile/src/support.ts:227). agent-device clips a row's box to the screen, so a row flush with an edge counts as cut off when the container reports hiddenContentAbove or hiddenContentBelow past it. A row flush with an edge with nothing hidden past it doesn't move, so a pull-to-refresh list doesn't refresh before tap({ position }). With center, a node more than a fifth from the middle is dragged only toward hidden content. A scrollIntoView that sends nothing isn't an action (packages/mobile/src/surface.ts:1737). The rules are under Scrolling in docs/reference/mobile.mdx.
  8. On the web, a screen swipe wheels at the viewport's center by distance of the nearest scrolling element there. The walk checks open shadow roots, climbs through slots, and includes body when the root element sets overflow (packages/web/src/support.ts:623). On desktop, the engine asks agent-desktop for distance times 10 app scroll units (a scrollbar step, content share, or page, depending on the app). Because agent-desktop doesn't report unit sizes, distance isn't a container share there. A distance of 0.65 (SCROLL_STEP) is 2 units regardless of speed. The deprecated momentum: 'fast' maps to that same distance, so the engine reads momentum and keeps it at 10 units (packages/desktop/src/surface.ts:1405).

The 800 ms step comes from 0.65 drags on the mobile benchmark's Huge Virtualized List, 3 runs each. The fling is how far the content moved past the finger's travel, as a share of the list. It has to stay under 0.35, the part of the last view a step leaves on screen.

DragiOS 27.2 simulator (list 758 pt)Android 16 emulator (list 2117 px)
400 msmore than a whole view, 3 of 3 runs0.32, 0.34, and once more than a whole view
600 ms0.34, 0.34, and once more than a whole view0.11, 0.12, 0.13
800 ms0.22, 0.22, 0.230.06, 0.07, 0.08
1000 ms0.12, 0.15, 0.180.00, 0.03, 0.05

Issue

Part of ENG-1434.

Verified

Ran it locally: yes

Runs are at ff4883c7 unless they name another commit. The commits after it change the desktop engine's units for momentum: 'fast' and its unit test, and otherwise only docs, comments, test titles, error message punctuation, and the changesets. The head, 8bf2e0e3, is those commits rebased onto main at 74e2abea, plus a commit that gives the swipe in main's new browser.clock integration test a distance and durationMs. That test passes in Chromium.

Devices: a dedicated iPhone 18 Pro simulator (iOS 27.2) and Pixel 7 AVD (API 36 google_apis arm64-v8a, animations off). Both runs used the mobile benchmark's Release builds made at 8a89af0e the way mobile.yml builds them, and the app hasn't changed since. There's no model key, so an agentic step with no recording fails.

Scroll and gesture flows, from each run's report.json (node node_modules/e2e/dist/cli/bin.js run --target <target>, agentic runs with --config e2e.agent.config.ts, Android agentic with --strict-cache):

ios-simulator     tests/flows-lists.e2e.ts               6 passed, 1 failed
ios-simulator     act completes Sticky Chrome Target     passed   (1 replayed)
ios-simulator     act completes Infinite Scroll List     passed   (1 replayed)
android-emulator  tests/flows-lists.e2e.ts               7 passed
android-emulator  act completes Sticky Chrome Target     passed   (--strict-cache, 1 replayed)
android-emulator  act completes Infinite Scroll List     passed   (--strict-cache, 1 replayed)
android-emulator  act completes Huge Virtualized List    passed   (--strict-cache, 1 replayed)
  • Sticky Chrome, the Gestures tests (one on momentum: 'fast'), Async States, and the 512-row list pass on both platforms. The iOS failure is the web view coupon form, which fails on main on this simulator.

Two throwaway tests, deleted before the commit, checked the hidden-content flags on Huge Virtualized List. The first called scrollIntoView on the last row, which the bottom of the screen cuts off. The second tapped the header flush with the list's top with position:

                  cut-off last row, scrollIntoView              flush header, positioned tap
ios-simulator     38.33 pt tall at y 835.67, then 56 at y 762   1316 ms, box unchanged
android-emulator  31 px tall at y 2369, then 57 at y 2218       1275 ms, box unchanged

Whole mobile benchmark suites at 8a89af0e, from each run's report.json (node node_modules/e2e/dist/cli/bin.js run --target <target>, agentic runs with --config e2e.agent.config.ts, Android agentic with --strict-cache):

ios-simulator     tests/                                 58 passed, 5 failed, 1 skipped
ios-simulator     sticky chrome: accept below the fold   passed
ios-simulator     gestures: long-press, then swipe left  passed   (momentum: 'fast', one drag)
ios-simulator     act completes Sticky Chrome Target     passed   (1 replayed)
android-emulator  tests/                                 62 passed, 0 failed, 1 skipped
android-emulator  sticky chrome: accept below the fold   passed
android-emulator  gestures: long-press, then swipe left  passed   (momentum: 'fast', one drag)
android-emulator  gestures: double-tap completes flow    passed
android-emulator  act completes Sticky Chrome Target     passed   (--strict-cache, 1 replayed)
  • The 5 iOS failures fail on main on this simulator: four keyboard dismissals in tests/device.e2e.ts and the web view coupon form.
  • The benchmark has no pager. The Gestures card advances one step per swipe, so a second drag would land on the next step's view.
  • The tests/ counts include one throwaway test, deleted before the commit, for a positioned tap on a list's first row.

At 8a89af0e, a throwaway test opened Huge Virtualized List, checked the header's top edge equals the list's (y 116 on iOS, 283 on Android), and tapped it with position. The header box didn't move on either platform. On iOS, the same test with the old edge rule (> and < in centringDrag) shows the 800 ms drag:

iOS simulatorold edge rulethis PR
positioned tap on the flush header2717 ms1422 ms
positioned tap on row 5 after it2136 ms715 ms

pnpm bench:ab -- tests/virtualized-table.e2e.ts tests/infinite-scroll.e2e.ts in apps/web-benchmark, Chromium. Each step covers 0.65 of the table instead of 0.75, so scrollUntilVisible takes about 14% longer there:

bench-ab: b3243302 (merge base with origin/main) vs 8a89af0e

apps/web-benchmark: e2e run --workers 1 tests/virtualized-table.e2e.ts tests/infinite-scroll.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 3.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.

Every test ran the same steps with the same outcome on every run of both builds.

Metricbase median (IQR)head median (IQR)change (95% CI)verdict
wall (process)18.13 s (18.12 s-18.16 s)20.45 s (20.44 s-20.46 s)+12.8% (+12.6% to +13.0%)slower
suite (sum of attempts)17.43 s (17.43 s-17.45 s)19.78 s (19.77 s-19.79 s)+13.4% (+13.3% to +13.6%)slower
action (events)16.57 s (16.55 s-16.58 s)18.83 s (18.82 s-18.85 s)+13.8% (+13.6% to +13.9%)slower
step screen.scrollUntilVisible16.93 s (16.93 s-16.94 s)19.28 s (19.27 s-19.29 s)+13.8% (+13.7% to +14.0%)slower
step app.open145 ms (144 ms-150 ms)145 ms (143 ms-146 ms)-1.7% (-5.2% to +1.7%)same, under the floor
step locator.tap114 ms (113 ms-116 ms)118 ms (112 ms-122 ms)+3.0% (-4.4% to +8.4%)same, under the floor
step expect.toHaveCount21 ms (20 ms-21 ms)21 ms (20 ms-21 ms)0.0% (-9.0% to +5.0%)same
step expect.toHaveText20 ms (19 ms-20 ms)20 ms (19 ms-20 ms)0.0% (-5.0% to +2.6%)same
step expect.toBeVisible2 ms (2 ms-2 ms)2 ms (2 ms-2 ms)0.0% (-18.4% to +22.5%)same
step expect.toBeHidden1 ms (1 ms-2 ms)1 ms (1 ms-1 ms)0.0% (-29.3% to 0.0%)same
Counterbasehead
events engine502-504575-576
Testbase median (IQR)head median (IQR)change (95% CI)verdict
tests/virtualized-table.e2e.ts › scrolls the windowed table to the Golden Row and claims it (web)14.53 s (14.53 s-14.53 s)16.76 s (16.75 s-16.77 s)+15.3% (+15.2% to +15.4%)slower

Testbed and web benchmark at 49c5cd08, the head, Chromium:

pnpm --filter @e2e-dev/testbed test                                            619 passed, 1 skipped
apps/web-benchmark  e2e run                                                    95 passed
apps/web-benchmark  CI=1 e2e run --config e2e.agent.config.ts --strict-cache   26 passed, 8 failed
  • The testbed test "scrollUntilVisible reaches every row of a long list in turn" fails with a step of 1.5, so it catches a step that skips rows.
  • The 8 web agentic failures need a model: five fail with "AI_GATEWAY_API_KEY is not set", and three are planted-bug judgments. The virtualized-table recording replays under --strict-cache, so no committed recording needs re-recording.

Firefox 159, with web({ browser: 'firefox' }) in the test file and the configs (not committed):

packages/web        vitest run tests/integration/lifecycle.test.ts             33 passed, 1 failed
apps/testbed        e2e run tests/scroll.e2e.ts                                5 passed
apps/testbed        e2e run                                                    595 passed, 15 failed, 1 skipped
apps/web-benchmark  e2e run tests/infinite-scroll.e2e.ts tests/virtualized-table.e2e.ts   2 passed
apps/web-benchmark  e2e run                                                    95 passed
apps/web-benchmark  CI=1 e2e run --config e2e.agent.config.ts --strict-cache   24 passed, 10 failed
  • The same tests fail on main (b3243302) in Firefox. The lifecycle failure is "refuses to swipe a node with no box even when its child is under aim": the swipe resolves instead of failing with NOT_ACTIONABLE. The 15 testbed failures are keyboard, fill, route, download, raw pointer, and screenshot tests. The agentic suite fails the same 8 tests as in Chromium, and the rich-text-editor and virtualized-table recordings go REPLAY_STALE, since they were recorded in Chromium.
  • The new lifecycle test for a pane in the document and in a shadow root passes. A throwaway test, deleted after, ran screen.swipe({ direction: 'down', distance: 0.5 }) and got the same offsets in Firefox and Chromium: 100 px on the testbed's 200 px pane, 200 px on a 400 px pane slotted into a shadow root, and half the viewport on a page where nothing else scrolls.

Docs screenshots: not captured. This repository has no local preview of the docs site. pnpm docs:check passes on the changed pages.

Not verified live: the desktop engine and its scroll unit counts (covered only by unit tests). Running it live needs a Mac with Accessibility permission, and no CI job runs it.

The Android video of Sticky Chrome at 8a89af0e is attached below.

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/6812b7ec-7f92-4253-b7eb-3ea2e6403801