Skip to content

Web: viewport DSL keyword (Playwright-style, web-only)#77

Closed
richjun wants to merge 2 commits into
devicelab-dev:mainfrom
richjun:feat/web-viewport
Closed

Web: viewport DSL keyword (Playwright-style, web-only)#77
richjun wants to merge 2 commits into
devicelab-dev:mainfrom
richjun:feat/web-viewport

Conversation

@richjun
Copy link
Copy Markdown
Contributor

@richjun richjun commented May 12, 2026

Summary

Adds a viewport keyword to the YAML DSL — Playwright-style, web-only. Not in upstream Maestro.

Two surfaces, same shape as playwright's viewport option:

url: https://example.com
viewport: {width: 1280, height: 720}     # flow header (initial size)
---
- openLink: /desktop
- viewport: {width: 390, height: 844}    # mid-flow resize
- assertVisible: "Mobile menu"
  • width / height required positive ints. Missing/zero/negative → parse-time error, browser not started.
  • Web (CDP) driver only. Mobile drivers return step type *flow.ViewportStep is not supported.
  • Backed directly by Emulation.setDeviceMetricsOverride (the same CDP primitive Playwright uses) — no shim.

Test plan

  • go test ./pkg/flow/... — parser + step matrix
  • go test ./pkg/driver/browser/cdp/ -run TestViewport — real Chromium resize, window.innerWidth verified
  • E2E: yaml with header viewport + 3 mid-flow resizes (1280→390→1920→1280) → 9/9 pass, JS-measured innerWidth × innerHeight matches every step
  • Invalid dims (0 / negative / missing) rejected at parse time across 3 separate flows

🤖 Generated with Claude Code

richjun added 2 commits May 12, 2026 16:07
Adds a web-only `viewport` surface that mirrors Playwright's two-tier
viewport model: an initial `viewport: {width, height}` in the flow
header (analogous to browser.newContext({ viewport })) and an in-flow
`viewport` step that resizes mid-run (analogous to page.setViewportSize).

- flow schema: new ViewportStep + Config.Viewport (positive int W/H,
  validated at parse time, no runtime workaround for missing/zero/neg).
- core: optional ViewportConfigurer interface so the executor can apply
  the flow-header viewport without coupling to the web driver.
- web (CDP) driver: SetViewport(w,h) calls Emulation.setDeviceMetrics
  via go-rod and updates the cached viewportW/H used by tap coords,
  orientation, and initPage for future tabs.
- executor: flow_runner applies Config.Viewport via the optional
  interface before any step runs; mobile drivers silently skip.

Mobile drivers fall through their existing default branch — the step
returns a clear "not supported" message rather than being silently
ignored.
- parser: viewport mapping accepted in header and in-flow; missing/
  zero/negative width or height rejected at parse time; isStepType
  recognizes the new keyword.
- step: ViewportStep registered in the step-type sanity matrix and
  Describe renders "viewport: WxH".
- CDP driver: TestViewportStep dispatches mid-flow resize and verifies
  window.innerWidth/innerHeight reflect the new size; SetViewport
  rejects non-positive dimensions; compile-time assertion that *Driver
  satisfies core.ViewportConfigurer so flow_runner can pick it up.
@richjun richjun closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant