feat(browser): add snapshot refs=aria mode

This commit is contained in:
Peter Steinberger
2026-01-15 10:16:33 +00:00
parent 0facc63019
commit 4f1a4ab072
13 changed files with 210 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import {
buildRoleSnapshotFromAiSnapshot,
buildRoleSnapshotFromAriaSnapshot,
getRoleSnapshotStats,
parseRoleRef,
@@ -67,4 +68,24 @@ describe("pw-role-snapshot", () => {
expect(parseRoleRef("12")).toBeNull();
expect(parseRoleRef("")).toBeNull();
});
it("preserves Playwright aria-ref ids in ai snapshots", () => {
const ai = [
'- navigation [ref=e1]:',
' - link "Home" [ref=e5]',
' - heading "Title" [ref=e6]',
' - button "Save" [ref=e7] [cursor=pointer]:',
" - paragraph: hello",
].join("\n");
const res = buildRoleSnapshotFromAiSnapshot(ai, { interactive: true });
expect(res.snapshot).toContain('[ref=e5]');
expect(res.snapshot).toContain('- link "Home"');
expect(res.snapshot).toContain('- button "Save"');
expect(res.snapshot).not.toContain("navigation");
expect(res.snapshot).not.toContain("heading");
expect(Object.keys(res.refs).sort()).toEqual(["e5", "e7"]);
expect(res.refs.e5).toMatchObject({ role: "link", name: "Home" });
expect(res.refs.e7).toMatchObject({ role: "button", name: "Save" });
});
});