跳到正文
DEV Community· Yash Kashyap·· 45 分鐘前AI 評分54

Auto-QA v2.1.0 根據 Dev.to 評論修正 Playwright MCP 工具的五類問題

Five Fixes Dev.to Commenters Caught in My Playwright MCP Tool (Auto-QA v2.1.0)

AI 導讀

Yash Kashyap 在 Auto-QA v2.1.0 中,根據 Dev.to 評論修正其 Playwright MCP 工具的五類問題。修正涵蓋彈窗和 DOM 可見性判斷、以環境變數讀取憑證並遮蔽輸出中的敏感內容,以及失敗時擷取當下 DOM 並檢查快照是否過時。

正文

Last week I wrote up how I split Playwright MCP discovery from $0 local replay in auto-qa. I mostly expected a couple of reactions and moved on, but the comment thread quickly turned into a real code review.

Almost every real upgrade in v2.1.0 came straight from people poking holes in v2.0.0 in those comments:

1. Ghost modal portals and display: contents

@tthanh2k6 pointed out two cases that broke my original visibility logic: display: contents wrappers return null for offsetParent just like position: fixed, and Radix/Headless UI portals often leave old hidden dialogs mounted in the DOM without a .hidden class. Checking .first() on matching dialogs meant executor.js could inspect a stale hidden portal instead of the open modal.

In v2.1.0, executor.js resolves the top-most rendered dialog across light DOM, slots, and open Shadow DOM using real CSS stacking contexts (z-index, :modal top-layer, transform) and ignores inert or aria-hidden="true" ghost nodes.

2. Switching the visibility helper to native element.checkVisibility()

@shahidhelalkhan suggested dropping most of the manual getComputedStyle ancestor loops in favor of Chromium's native element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true, contentVisibilityAuto: true }), while keeping explicit checks for inert, aria-hidden, and zero-size rects.

discover.js and executor.js now share one scripts/browser-dom.js helper that uses checkVisibility() (with a fallback for older runtimes), checks rendered child boxes for display: contents wrappers, skips deferred content-visibility: auto sections, and walks open shadow hosts for hidden, inert, and aria-hidden="true".

3. ${ENV_VAR} placeholders instead of hardcoded .fill() credentials

@wrobeltomasz asked how compiled .spec.ts files handle login secrets. In v2.0.0, compiler.js literally emitted whatever string sat in plan.json.

v2.1.0 adds scripts/env-utils.js with strict identifier validation (^[A-Z_][A-Z0-9_]*$), fail-closed requireEnv() lookups in compiled .spec.ts, default prefix allowlisting (QA_,AUTO_QA_,TEST_) in MCP mode, and pre-truncation redaction across stdout, console errors, Markdown reports, JSON reports, and failure snapshots.

4. Failure-time scoped snapshots + staleness warnings

Through the thread with @eliashivemind, two gaps became obvious: re-crawling with discover.js after a failure loses the live modal/logged-in DOM state, and patching later from an old snapshot wastes tokens if the app code changed in the meantime.

executor.js now reads the failing DOM (scoped to the active blocking modal if open) inside the step catch block before screenshot capture or browser teardown, writing failure-step-N-context.json with capturedAt and Git HEAD. There is also a check-context-freshness CLI subcommand and auto_qa_check_context_freshness MCP tool (scripts/context-freshness.js) that warn when project source files or Git HEAD changed since capture, while ignoring .git, node_modules, build folders, and QA artifacts.

5. Dynamic counter/badge normalization in selectors

After reading how @v0val0x normalizes changing counters and badges before hashing mobile screens, I added a fallback tier (normalizeDynamicLabel()) in executor.js. Exact and substring locators still run first; only if they miss does the runner match changing trailing counters like Cart (1) -> Cart (2) or Notifications (4) -> Notifications (14) inside the active modal scope (guarded so short or numeric-only labels like "1" never collide).

Extra bugs caught during our own audit before tagging

Before pushing v2.1.0, a final pass caught four more bugs in my own draft code:

  • fill and select field targets had bypassed ${ENV_VAR} validation.
  • A modal detaching mid-failure could have widened failure capture back to the full page instead of preserving modal scope.
  • Early console errors could truncate a secret before the step that registered it, so permitted plan secrets are now registered before the first log.
  • Navigation could race ahead of the CDP redirect/SSRF guard installation, and CLI/MCP outputs now use atomic temp-file replacement (scripts/write-output.js) instead of overwriting existing paths in place.

Everything is covered by 26 automated checks (9/9 security audit units + 17/17 Playwright/CLI/MCP feature tests).

Release notes and code: https://github.com/yashh1323/auto-qa/releases/tag/v2.1.0

來源:DEV Community · dev.to