Screenshots¶
Screenshots are evidence from the running product, not illustrations.
Rules¶
- Use a dedicated test environment and test user.
- Use synthetic demo data.
- Keep credentials in environment variables or a secret manager.
- Mask secrets, personal data, billing details, and IDs.
- Do not upload screenshots to third-party services without authorization.
- Do not modify application source just to make a capture easier.
Never substitute an AI-generated mockup, a design file, or recreated HTML for a real application screenshot.
Docs-only Playwright config¶
DocsForge creates a separate config so screenshot tests do not share state with the app's E2E or visual-regression suites:
playwright.docs.config.ts
.documentation/screenshots/
inventory.yml
specs/
README.md
docs/assets/screenshots/
The generated config:
- points
testDironly at documentation specs; - fixes viewport, locale, timezone, theme, and reduced motion;
- disables animations;
- uses one worker for deterministic output;
- writes reports and results under
.documentation/screenshots/; - does not share
snapshotDirwith visual regression.
If you spread a Playwright device preset, set viewport after the spread so the
preset does not override it.
Authentication¶
Prefer a Playwright setup project that signs in once and saves storageState:
import { test as setup, expect } from "@playwright/test";
import path from "node:path";
const authFile = path.join(".documentation", "screenshots", ".auth", "owner.json");
setup("authenticate", async ({ page }) => {
await page.goto("/login");
await page.getByLabel("Email").fill(process.env.DOCS_USER_EMAIL!);
await page.getByLabel("Password").fill(process.env.DOCS_USER_PASSWORD!);
await page.getByRole("button", { name: "Sign in" }).click();
await expect(page).not.toHaveURL(/\/login/);
await page.context().storageState({ path: authFile });
});
Never hardcode credentials. Never use a production account.
Demo data¶
Use, in order:
- a project-provided seed command;
- a documented fixture/API setup;
- a database snapshot for a local test environment;
- UI-driven setup only when it is fast and idempotent.
Use fixed names, dates, amounts, and IDs. Use example.com for emails. Never
point at production.
Capture workflow¶
For each documented workflow:
- Identify the route and role.
- Prepare data and auth state.
- Navigate to the starting page.
- Perform the documented actions with the same labels as the guide.
- Capture starting, action, and result states.
- Assert the expected UI state before each capture.
- Save to
docs/assets/screenshots/<area>/<step>.png. - Reference the image next to the step.
- Update the inventory.
Example:
import { test, expect } from "@playwright/test";
import path from "node:path";
const out = (name: string) =>
path.join("docs", "assets", "screenshots", "members", name);
test.use({ storageState: ".documentation/screenshots/.auth/owner.json" });
test("invite member", async ({ page }) => {
await page.goto("/settings/members");
await expect(page.getByRole("heading", { name: "Members" })).toBeVisible();
await page.screenshot({ path: out("01-members.png") });
await page.getByRole("button", { name: "Add member" }).click();
await expect(page.getByRole("dialog")).toBeVisible();
await page.screenshot({ path: out("02-invite-dialog.png") });
await page.getByLabel("Email").fill("demo.member@example.com");
await page.getByLabel("Role").selectOption("Member");
await page.getByRole("button", { name: "Send invitation" }).click();
await expect(page.getByText("Invitation sent")).toBeVisible();
await page.screenshot({ path: out("03-invitation-sent.png") });
});
Locators¶
Prefer, in order:
getByRolewith the accessible name;getByLabel/getByPlaceholder;- stable visible text;
data-testid;- scoped CSS selectors only as a last resort.
Never depend on DOM order or generated class names.
Inventory¶
Every documented screenshot has an entry:
version: 1
screenshots:
- id: members-invite-01
guide: docs/user/guides/invite-member.md
route: /settings/members
role: workspace-owner
spec: .documentation/screenshots/specs/members.spec.ts
output: docs/assets/screenshots/members/01-members.png
captured: 2026-11-11
status: current
The inventory enables targeted regeneration: after a UI change, only entries whose route, spec, or guide is affected are recaptured.
No browser UI¶
If the product has no browser UI:
- mark screenshots
NOT APPLICABLE; - capture real CLI output as text blocks or terminal screenshots;
- do not install a browser stack the product cannot use.
Validation¶
npx playwright test -c playwright.docs.config.ts
node ~/.documentation-toolkit/scripts/audit-project.mjs --root . --domain screenshots
The audit checks missing files, orphaned inventory entries, missing specs, broken image references, stale capture dates, and public-safety leakage.