Playwright and Vera: import specs, export tests

Vera runs tests on Playwright, so a Playwright spec is the closest format it reads. The importer parses each spec file and maps page actions, literal locators and expect() assertions onto Vera steps. Going the other way, any Vera test exports as a @playwright/test file.

What comes across

  • The Playwright converter is deterministic: the same file gives the same tests, with no AI call and no AI credits spent.
  • page.goto(url) becomes a goto step; click, dblclick, fill, type, check, uncheck, hover, selectOption and press on a locator become the matching Vera actions.
  • Locators with a literal argument — page.locator(css), getByTestId, getByText, getByPlaceholder, getByAltText and getByTitle — are rewritten as CSS or text= selectors.
  • expect(page).toHaveTitle() and toHaveURL() become title and URL assertions; a regular-expression argument becomes a matches condition.
  • Locator matchers toBeVisible, toBeHidden, toHaveText, toContainText and toHaveValue become visible, hidden, text and value assertions.
  • waitForSelector, waitForURL and waitForTimeout become wait steps, and page.screenshot() becomes a screenshot step.
  • request.get/post/put/patch/delete calls become api-request steps, with their literal headers and body.
  • On export, a test downloads as a .spec.ts file that imports test and expect from @playwright/test.
  • On export, if/else and loop steps become real if and for blocks, and reusable flows are inlined into the file.
  • On export, {{variable}} tokens become environment-variable reads, unless an earlier extract or api-request step produced the value, in which case the spec uses that local.

What does not

  • getByRole and getByLabel locators have no faithful CSS or text form, so those statements are not converted; they are listed as warnings for manual or AI conversion.
  • Page objects, helper functions, loops and variable indirection are not converted — that logic is not a step list.
  • Setup and teardown hooks (beforeEach and friends) are skipped with a warning; re-add the setup to each test, or factor it into one reusable flow.
  • On export, an accessibility-audit step becomes commented-out @axe-core/playwright code that you install and enable yourself.
  • On export, a step with no Playwright equivalent becomes a TODO comment at the spot it stood, rather than being dropped.

How to set it up

  1. Open a project's Tests page and choose Import tests, then pick your .spec.ts files. The format is detected from each file.
  2. Read the warnings and the unresolved count before trusting the test count: they name every statement that was not converted.
  3. Optionally tick the AI conversion box to convert what the importer could not read. It is off by default because it spends AI credits, and every step it writes is flagged for review.
  4. Or convert from the repository: npx vera-agent init --import playwright finds the specs and uploads them through the CI API, which needs Pro or above on Vera's cloud (self-hosted installs include it). The dashboard import works on every plan.
  5. To take a test back out, open its Export as code menu on the Tests page and choose Playwright.

Questions

Does importing Playwright tests into Vera use AI?

No. The Playwright converter is deterministic and spends no AI credits. AI conversion is a separate opt-in for the statements the converter cannot read, and every step it writes is flagged for review.

Can I export Vera tests to Playwright?

Yes. Any test exports as a .spec.ts file for @playwright/test. The translation is deterministic, and a step with no Playwright equivalent becomes a TODO comment where it stood.

Why did some of my Playwright statements not import?

Locators such as getByRole and getByLabel, page objects, helpers and loops have no direct step form. The import lists each one as a warning, so you can convert it by hand or with opt-in AI conversion.

Are Playwright beforeEach hooks imported?

No. Hooks are skipped with a warning. Re-add the setup to each test, or extract it once as a reusable Vera flow.

Read more

Start free