agentleFS
RoninForgeRoninForge/roninforge-playwright/skills/playwright-validate/SKILL.md

playwright-validate

Skill0 starsChanged 7 months agoMITView on GitHub

Scan a Playwright codebase for tracked anti-patterns. Most are reliably grep-detectable: text/CSS engine selectors, page.$/$$ ElementHandles, page.waitForTimeout, isVisible/textContent booleanised, page.route after goto, hardcoded credentials, missing forbidOnly, deprecated playwright-github-action, headless: false committed, mode 'serial' default. A few (assertion missing await, untyped test.extend) need manual review.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 1 is distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When auditing an existing Playwright suite, when reviewing a PR that touches *.spec.ts files, or before promoting a suite from "smoke" to …

    line 10
  2. Very specific:

    Run from the repo root. The patterns assume tests live under tests/ or e2e/.

    line 14
  3. Very specific:

    Every line returned should have an await immediately before expect(.

    line 42
  4. Distinctive:

    Every hit is wrong in a test body.

    line 50
  5. Very specific:

    Every hit loses auto-retry.

    line 76
  6. Very specific:

    Use Playwright's expect so failures show up in trace and reporter.

    line 85
  7. Very specific:

    Use trace: "on-first-retry" for CI.

    line 160

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Validate a Playwright Codebase

When to Use

When auditing an existing Playwright suite, when reviewing a PR that touches *.spec.ts files, or before promoting a suite from "smoke" to "blocking CI." The grep patterns below catch the regressions documented in the playwright-anti-patterns rule.

Scope

Run from the repo root. The patterns assume tests live under tests/ or e2e/. Adjust the path if your project differs.

TEST_DIR=tests   # or e2e, or wherever your *.spec.ts live

CRITICAL: hardcoded credentials in test files

# Heuristic - email-like or password-like string literals on any fill() line.
# The two-step pipe handles both forms:
#   page.fill("#email", "alice@acme.com")          // email is the SECOND arg
#   page.getByLabel("Email").fill("alice@acme.com") // email is the FIRST arg
grep -rnE '(\.fill\(|page\.fill\()' --include='*.ts' "$TEST_DIR" | grep -E '"[^"]+@[^"]+\.[^"]+"'
grep -rnE '(\.fill\(|page\.fill\()' --include='*.ts' "$TEST_DIR" | grep -iE '"(p[a@]ssw[o0]rd|hunter2|admin|secret)"'

Manual triage. The password grep will false-positive on getByLabel("Password").fill(process.env.E2E_PASS!) because "Password" matches the pattern and .fill( is on the same line. Ignore matches where the .fill( argument is a process.env.* reference. The email grep does not have this problem in practice. If the email literal is a fixture domain (@example.com), it may be intentional - but the password should still come from env.

CRITICAL: missing await on web-first assertion

# Lines starting with `expect(` (no await) followed by a chained matcher.
# This is a heuristic - manual triage required because `expect(value).toBe(...)`
# on synchronous values is legitimate.
grep -rnE '^\s*expect\(.*\)\.(toBeVisible|toBeHidden|toHaveText|toHaveURL|toHaveTitle|toContainText|toHaveCount|toBeAttached|toBeEnabled|toBeDisabled|toBeFocused)' --include='*.ts' "$TEST_DIR"

Every line returned should have an await immediately before expect(. Anything without await is a no-op.

ERROR: page.waitForTimeout

grep -rnE '\bpage\.waitForTimeout\(' --include='*.ts' "$TEST_DIR"

Every hit is wrong in a test body. Replace with the web-first assertion that justifies the wait.

ERROR: text/CSS/XPath engine selectors

# `text=`, `css=`, `xpath=` engine selectors in click/fill/locator calls.
# The character class covers double-quote, single-quote (\x27), and backtick.
grep -rnE "(click|fill|locator)\((\"|\x27|\`)(text=|css=|xpath=)" --include='*.ts' "$TEST_DIR"

Replace with page.getByRole / getByLabel / getByText / getByPlaceholder.

ERROR: page.$() / page.$$() ElementHandles

grep -rnE '\bpage\.\$\$?\(' --include='*.ts' "$TEST_DIR"

Both return ElementHandle (snapshot, racy). Replace with page.locator(...) or, better, a getBy* call.

ERROR: expect(await locator.isVisible()).toBeTruthy()

grep -rnE 'expect\(await\s+\S+\.(isVisible|isHidden|isEnabled|isDisabled|isChecked|isEditable|textContent|innerText|inputValue)\(\)\)' --include='*.ts' "$TEST_DIR"

Every hit loses auto-retry. Replace with the web-first equivalent: await expect(loc).toBeVisible(), toHaveText(), etc.

ERROR: assert from node:assert

grep -rnE 'from\s+("|\x27)node:assert("|\x27)' --include='*.ts' "$TEST_DIR"
grep -rnE 'require\(("|\x27)assert("|\x27)\)' --include='*.ts' "$TEST_DIR"

Use Playwright's expect so failures show up in trace and reporter.

ERROR: missing forbidOnly

# In playwright.config.ts (or .js/.mts) - confirm forbidOnly is set.
# -r is required: BSD grep on macOS does NOT recurse without it, even with --include.
grep -rlE 'defineConfig\(' --include='playwright.config.*' . 2>/dev/null | while read -r f; do
  grep -q 'forbidOnly' "$f" || echo "$f: forbidOnly missing"
done

forbidOnly: !!process.env.CI should be in the top-level defineConfig({...}).

ERROR: missing webServer block

grep -rlE 'defineConfig\(' --include='playwright.config.*' . 2>/dev/null | while read -r f; do
  grep -q 'webServer' "$f" || echo "$f: webServer missing - tests may race the dev server"
done

ERROR: Page / Locator imported from playwright (not @playwright/test)

grep -rnE 'from\s+("|\x27)playwright(-core)?("|\x27)' --include='*.ts' "$TEST_DIR"

Use import type { Page, Locator } from "@playwright/test".

WARN: page.waitForSelector followed by an action

grep -rn -A 2 'page\.waitForSelector' --include='*.ts' "$TEST_DIR"

Manual triage. If the next line is a click/fill on the same selector, the wait is redundant.

WARN: page.route after page.goto (race condition)

# Heuristic two-step: list files with both, then manually inspect order.
for f in $(grep -rl 'page\.route' --include='*.ts' "$TEST_DIR"); do
  if grep -q 'page\.goto' "$f"; then
    echo "=== $f ==="
    grep -nE 'page\.(route|goto)' "$f"
  fi
done

Manual triage. page.route(...) should appear before page.goto(...) for the relevant route.

WARN: route handler with no continue or fallback

# Files with page.route but no continue/fallback at all
for f in $(grep -rl 'page\.route\|context\.route' --include='*.ts' "$TEST_DIR"); do
  grep -qE 'route\.(continue|fallback)' "$f" || echo "$f: route handler with no continue/fallback - non-matching requests may hang"
done

WARN: headless: false in config

grep -rnE 'headless\s*:\s*false' --include='playwright.config.*' --include='*.ts' .

Headless is the default. Override ad-hoc with --headed. Don't commit it.

WARN: trace: "on" in config

grep -rnE 'trace\s*:\s*("|\x27)on("|\x27)' --include='playwright.config.*' .

Use trace: "on-first-retry" for CI. "on" produces large artifacts every run.

WARN: untyped test.extend

# test.extend without a type parameter
grep -rnE '\bextend\(\s*\{' --include='*.ts' "$TEST_DIR" | grep -v '<'

Manual triage. Should be base.extend<Fixtures>({...}).

WARN: data-testid overuse when role exists

This needs manual review - grep cannot tell whether a role-based locator would work. Spot-check getByTestId(...) calls; if the underlying element is a <button>, <a>, <input>, or has a heading role, prefer getByRole.

grep -rnE '\bgetByTestId\(' --include='*.ts' "$TEST_DIR"

WARN: deprecated microsoft/playwright-github-action

grep -rnE 'microsoft/playwright-github-action' --include='*.yml' --include='*.yaml' .github/

Replace with raw npx playwright install --with-deps + npx playwright test.

WARN: test.describe.configure({ mode: 'serial' }) as default

grep -rnE "describe\.configure\(\s*\{\s*mode\s*:\s*('|\")serial" --include='*.ts' "$TEST_DIR"

Serial mode disables isolation and skips remaining tests on first failure. Use only when shared session is truly required - independent of any other check above.

SUGGESTION: hardcoded viewport over devices

grep -rnE 'viewport\s*:\s*\{' --include='*.ts' "$TEST_DIR"

Manual triage. If the dimensions match a known device profile, use ...devices['iPhone 14'] or similar.

Output format

Tag each finding with severity (CRITICAL / ERROR / WARN / SUGGESTION) and emit file:line - one-line problem - one-line fix. Group by file. End with N critical, N errors, N warnings, N suggestions.

What this skill does NOT catch

  • data-testid overuse where role is appropriate (manual review).
  • Logic bugs in fixture lifecycle.
  • POM design quality.
  • Visual regression baseline OS mismatch (__screenshots__/ exists for the wrong OS).
  • Real flake from network timing.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.