Step Helpers

zoom

Zoom into a UI element during a test step for the demo video.

What it does

zoom(locator, level) captures an element's bounding box and stores viewport-relative coordinates as a Playwright annotation. During video generation, the renderer crops and scales the video to zoom into the recorded position during the step's time window.

Usage

import { zoom } from 'playwright-recast'

const sidebar = page.locator('.sidebar-panel')
await zoom(sidebar, 1.3)

Parameters

ParameterTypeDefaultDescription
locatorLocator(required)Playwright Locator pointing to the element to zoom into
levelnumber1.5Zoom level: 1.0 = no zoom, 2.0 = 2x closer

How it works

  1. Gets the element's bounding box via locator.boundingBox()
  2. Computes the center as viewport-relative fractions (0.0--1.0)
  3. Stores { x, y, level } as a zoom annotation on the current test
  4. During rendering, enrichZoomFromReport() reads these annotations and applies crop-and-scale zoom with smooth easing transitions

Zoom coordinates

The stored coordinates use viewport-relative fractions:

FieldRangeDescription
x0.0--1.0Center X (0 = left edge, 1 = right edge)
y0.0--1.0Center Y (0 = top edge, 1 = bottom edge)
level1.0+Zoom factor (1.0 = no zoom)

Example in a BDD step

import { When } from './fixtures'
import { narrate, zoom } from 'playwright-recast'

When('the user opens the sidebar', async ({ page }, docString?: string) => {
  narrate(docString)
  const sidebar = page.locator('.sidebar-panel')
  await zoom(sidebar, 1.3)
  await sidebar.click()
})
When the user opens the sidebar
  """
  Let's take a closer look at the sidebar navigation.
  """

The video will zoom into the sidebar element during this step, then smoothly zoom back out when the next step begins.

On this page