Browser e2e tests

From dxos/dxos · View interactive version

Browser e2e tests is an AI agent skill from the GitHub repository dxos/dxos. Authoring browser end-to-end tests for the Composer app with Playwright. Use when writing, editing, or reviewing *.spec.ts under packages/apps/composer-app/src/playwright, adding page-object helpers, or deciding how to target elements (always data-testid, never labels/roles).

How to use this skill

Skill file

Browser E2E Tests (Playwright)

Browser e2e drives the real Composer app in a browser — the only tier that verifies _perceived_

behavior: interactivity during async work, no false empty states, and full click→render flows.

Distinct from agent-eval-tests (the LLM agent harness) and storybook interaction tests.

Location: packages/e2e/composer-e2e/src/playwright/ — *.spec.ts specs, root page-objects

(app-manager.ts), and per-plugin helpers under plugins/ (re-exported from plugins/index.ts).

The MEASUREMENT harnesses (startup, perf-*, dev-*, welcome-focus) stay in

packages/apps/composer-app/src/playwright/, beside the budget tasks that gate on them.

The full authoring guide is packages/e2e/composer-e2e/BEST-PRACTICES.md — this skill is the

short form; that file is the one to read before writing a spec.

Every test binds to an `.mdl` QA flow

A test QA-n block is the specification of a journey; a spec is one unattended execution of it.

Declare the binding on BOTH sides — a Playwright tag on the test and an automated: entry on the

flow — and scripts/check-qa-coverage.mjs (a check job step) fails when they disagree:

test('create document', { tag: ['@QA-1'] }, async () => { … });
test QA-1: Spaces and documents
  automated:
    - composer-e2e:basic.spec.ts#Basic tests › create document

Write the flow first if none exists — APP.mdl for a journey crossing plugins, the plugin's

PLUGIN.mdl otherwise. A prefixed tag (@review:QA-1) binds to that plugin's spec; register the

prefix in SPEC_FILES in the checker.

A skipped test still carries its tag but stays out of automated: — skipping is inherited from

test.describe.skip, and a flow listing a test that never runs reads as automated while nothing

exercises it.

Golden rule: target by `data-testid`, never by label, text, or role-name

Labels and visible text come from translations.ts and change with copy/i18n; role-names are

ambiguous when several controls share a name. data-testid is the only stable selector.

testid is a source gap to fix, not a reason to fall back to a label. Never let a translated string

become a selector.

How to add testids

Form.Root / Form.Submit forward it (e.g. Form.Submit renders data-testid='save-button').

the action sets action.properties.testId — a label/icon alone produces no testid. Add

properties: { testId: 'inbox.message.reply' } to the action spec; do not target the menu label.

deck.plank, create-object-form). E.g. inbox.mailbox.row, inbox.message.header,

inbox.draft.send.

Selector priority (only when a testid genuinely can't exist yet)

  1. data-testid — the default; add it if missing.
  2. Framework/ARIA _state_ that encodes behavior, not copy: aria-selected, aria-current, ids/

classes the framework sets (e.g. a Mosaic tile's id, dx-current/dx-selected).

  1. Role — only scoped inside a testid'd container, never role + translated name as the primary hook.

Visible text/labels are for assertions about content, never for locating controls.

Spec structure

Follow the existing shape (basic.spec.ts):

import { expect, test } from '@playwright/test';
import { AppManager } from './app-manager';

// The PWA service worker breaks routing/interception; require it disabled.
if (process.env.DX_PWA !== 'false') {
  throw new Error('run with DX_PWA=false');
}

test.describe('Inbox', () => {
  let host: AppManager;
  test.beforeEach(async ({ browser }) => {
    host = new AppManager(browser, false);
    await host.init();
  });
  test.afterEach(async () => {
    await host.closePage();
  });

  test('selecting a thread opens the companion', async () => {
    // Drive via page objects + testids — no inline selectors, no labels.
  });
});

Page objects

Every interaction lives behind a page-object so specs read as intent, not selectors.

createObject({ type: '<Typename label>' }) (picks the type by its typename label, e.g.

'Mailbox'), enablePlugin('org.dxos.plugin.<x>') (via the /!dxos:plugin-registry route),

deck.plank(nth).

page-object) and re-export from plugins/index.ts. Keep all selectors inside the helper.

Running

(e2ePreset, vite preview on port 4173, pre-built bundle).

via test.skip(browserName !== 'chromium').

schedule and a dispatch; a draft PR skips them. They are scoped to affected projects except on the

schedule and a dispatch. A dispatch forces every suite to run rather than replay; only=e2e skips

the other jobs. The schedule and a dispatch also publish every test's outcome to PostHog as

ci.e2e-test (DASHBOARD.md).

Its profile defaults to Fast 3G + 2x CPU and each field is overridable via DX_HARNESS_LATENCY_MS,

DX_HARNESS_DOWN_MBPS, DX_HARNESS_UP_KBPS, DX_HARNESS_CPU (throttleProfile in

harness-helpers.ts). Override when the default cannot reach ready inside waitForReady.

Waiting & stability

(await expect(locator).toBeVisible()), locator.waitFor(), and assert on framework state

(aria-selected) rather than screenshots or copy where behavior is the thing under test.

Data setup

production code paths.

bridge — never live credentials, never real network to third parties. Mock external HTTP.

Anti-patterns

| Don't | Do |

| ---------------------------------------------------- | -------------------------------------------------------------- |

| getByRole('button', { name: 'Reply' }) | add properties.testId → getByTestId('inbox.message.reply') |

| getByText('Send') / getByLabelText('To') | testid on the field/control |

| Fall back to a label when the testid is missing | add the testid to the component |

| page.waitForTimeout(1000) | expect(locator).toBeVisible() / waitFor() |

| Inline selectors scattered across a spec | a page-object helper under plugins/ |

| Live provider credentials / real third-party network | mock + a gated test bridge; DX_PWA=false |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.