# Run Playwright tests

> Run test files written for Playwright on Retest, and know what runs, what is refused and what differs.

Source: https://rehearsal.dev/retest/scaling-up/playwright-tests

`retest run --playwright` runs test files written for Playwright, unchanged, as far as Retest's compatibility goes. Anything beyond it fails where it is used, and names what it met.

```sh
npx retest run --playwright --browser "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --base-url http://127.0.0.1:3000
npx retest run --playwright tests/checkout.spec.ts --browser /usr/bin/chromium --base-url http://127.0.0.1:3000
```

- Files end in `.spec.ts`, `.spec.js`, `.spec.mts` or `.spec.mjs`, or the same with `.test.`. With no files named, Retest takes every `.spec.` file under the folder.
- `@playwright/test` resolves to Retest's own `@rehearsal-labs/retest/playwright`. Playwright does not have to be installed.
- `playwright.config.ts` is not read. The browser, the base URL, the workers and the budgets come from the command line, or from `retest.config.ts`.
- The report's first line says `playwright compatibility`, so nobody takes the run for Playwright's own.

## What runs

| Area | Supported |
| --- | --- |
| Tests | `test`, `test.describe`, `test.beforeEach`, `test.afterEach`, `test.step` and the `page` fixture |
| Pages | `page.goto`, `reload`, `goBack`, `goForward`, `title` and `page.keyboard.press` |
| Locators | `getByRole`, `getByLabel`, `getByText`, `getByTestId`, `getByPlaceholder` and `locator`, with `first`, `last` and `nth` |
| Actions | `fill`, `click`, `hover`, `press`, `check`, `uncheck` and `selectOption` |
| Checks | `toBeVisible`, `toBeHidden`, `toBeChecked`, `toBeEnabled`, `toBeDisabled`, `toHaveText`, `toContainText`, `toHaveCount`, `toHaveValue`, `toHaveURL` and `toHaveTitle`, each also after `.not` |
| Values | `toBe`, `toEqual`, `toContain`, `toMatch`, `expect.soft` and `expect.poll` |

`{ timeout }` on those calls goes to Retest's own, which can shorten a budget and never lengthen it.

## What is refused

Everything else fails as unsupported, by name, such as "page.getByAltText is not supported yet by Retest's Playwright compatibility." Nothing is skipped or dropped.

- Options Retest does not take, such as `click({ force })`, `goto(url, { waitUntil })` or `press(key, { delay })`.
- `test.skip`, `test.only`, `test.use`, test details, a titled hook and any fixture other than `page`.
- `page.url`, which Playwright reads at once where Retest has to ask the page.
- `selectOption` with a bare string, a list or `{ index }`. Name the option with `{ label }` or `{ value }`.
- `getByRole('row', { name })`. Take the row by position with `nth()`, or find a cell by name.
- Any locator on a page that holds an open shadow root, since Retest does not look inside one.

## Where it differs

- The rules are Retest's. A test with no assertion fails, a locator that matches several elements is ambiguous, and an action is sent once.
- Budgets are Retest's: a test has 60 seconds and an action 10. Both runners give a check 5 seconds.
- `selectOption` chooses with the keyboard, so the page hears the keys as well as `input` and `change`.
- Names come from Chrome's accessibility tree, not from Playwright's own reckoning.
- `goBack` and `goForward` with no entry that way fail instead of answering `null`.

## The comparison

Retest's repository runs a fixed set of Playwright tests twice: once under Playwright 1.63.0 and once under Retest, in the same Chrome. It compares them case by case.

| Cases | Count |
| --- | --- |
| Run by both, with the same steps and the same outcome | 38 of 44 |
| Refused by Retest by name, as declared | 6 of 44 |
| Left out: sign-in state set up in `playwright.config.ts` | 4 |

The six refused cases find a table row by name or pass `selectOption` a bare string. The full table is in [the compatibility report](https://github.com/rehearsal-labs/retest/blob/main/docs/compatibility/playwright.md).

> [!NOTE]
> These counts describe that set of tests only. They say nothing about a Playwright suite of yours, so run it and read what is refused.
