@codepress/interactions-playwright

中文文档
1.1.0发布于 2026/11/06Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 2793

Playwright helpers that run the CodePress Interactions UI checks in tests: capture a snapshot, list findings, assert none

原始使用文档

@codepress/interactions-playwright

Playwright helpers that run the CodePress Interactions UI checks on a page under test: overlapping elements, content spilling out of its box, horizontal page scroll, controls out of reach, small tap targets (touch), clipped text and broken images.

npm install --save-dev @codepress/interactions-playwright
import { test } from "@playwright/test";
import { expectNoFindings, findIssues } from "@codepress/interactions-playwright";

test("checkout has no layout findings", async ({ page }) => {
  await page.goto("/checkout/42");
  await expectNoFindings(page, { routeSegments: ["checkout"] });
});

A failure lists one line per finding: the check, the elements (test ID, or a structural path such as #cart/div/button when there is none), the measured evidence and the fingerprint.

2 UI findings on /checkout/42. Pass a fingerprint in ignoreFingerprints to accept one.
  "layout.overlap checkout × promo on /checkout/:id @1280x800: overlap_px=3520 … subject_blocked_points=5 … center_blocked subject_text_covered … [590f6922417e2a04f8d6c9341daf02c1]"

Findings are pointers, not verdicts: each says what was measured, and you decide whether it is a bug. Sorting puts blocked controls first, then covered or clipped text, then the rest, then decorative layers and content-free findings (stacked or cropped images); it never drops one.

API

  • captureSnapshot(page, options?) → { body, sha256 }: walks the page with the SDK's snapshot walker in one pass, so the body is never torn.
  • findIssues(page, options?) → Finding[]: the checks on the page as it is now, sorted.
  • expectNoFindings(page, options?): fails the test when findIssues returns anything.

Options (all optional):

OptionDefault
rootwhole documentCSS selector of the subtree to walk
ignorenoneextra selector for subtrees to leave out; [data-layout-ignore] always applies
routefrom the URLroute template recorded on findings and used by fingerprints
routeSegments[]literal path segments kept in the default route template (others become :id)
maxElements50000element limit
themethe page's prefers-color-scheme"light", "dark" or "unknown" to record, for apps with their own theme toggle (Playwright's colorScheme / page.emulateMedia set the default)
testIddefaultTestIdFilter(value, element) => string | null: which data-interaction-id / data-testid values to record, as the browser SDK's testId option. It runs in the page, so it must be self-contained, like a page.evaluate callback; a name the page does not have fails the capture. A name the page does have, such as a test variable called status, or any other runtime error in the hook, drops the ID with no error, so check the snapshot's IDs when you write a hook. Write out the rule your app uses so fingerprints match production, calling globalThis.__codepressInteractions.defaultTestIdFilter(value) where it calls the default. (value) => value keeps every ID
ignoreFingerprints[]fingerprints to leave out (known findings accepted for now)
eventsnoneprotocol v2 events to run the click and stability checks over too
checks and thresholdssee detect options

Fingerprints are stable across scroll offsets, runs and machines: they hash the check, the route template, the viewport width band and the elements' identities, never coordinates.

License

Apache-2.0

版本与发布记录

@codepress/interactions-playwright 共发布 3 个版本,首次发布于 2026/11/05;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.0latest2026/11/064 天前
1.0.02026/11/054 天前
0.0.0-stage2026/11/054 天前

关于 @codepress/interactions-playwright 的常见问题

@codepress/interactions-playwright 是什么?

Playwright helpers that run the CodePress Interactions UI checks in tests: capture a snapshot, list findings, assert none

如何安装 @codepress/interactions-playwright?

在项目目录运行 npm install @codepress/interactions-playwright,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@playwright/test(>=1.40)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@codepress/interactions-playwright 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codepress/interactions-playwright 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@codepress/interactions-playwright 可以商用吗?

@codepress/interactions-playwright 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@codepress/interactions-playwright 的下载量有多少?

根据 npm 官方下载统计,@codepress/interactions-playwright 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,793 次,日均约 93 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codepress/interactions-playwright 还在维护吗?

最新版本 1.1.0 发布于 2026/11/06(4 天前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/11/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。