* Resolve a selector that may be a @ref (e.g., "@e3", "@c1") or a CSS selector. * Returns { locator } for refs or { selector } for CSS selectors.
(selector: string)
| 86 | * Returns { locator } for refs or { selector } for CSS selectors. |
| 87 | */ |
| 88 | async resolveRef(selector: string): Promise<{ locator: Locator } | { selector: string }> { |
| 89 | if (selector.startsWith('@e') || selector.startsWith('@c')) { |
| 90 | const ref = selector.slice(1); // "e3" or "c1" |
| 91 | const entry = this.refMap.get(ref); |
| 92 | if (!entry) { |
| 93 | throw new Error( |
| 94 | `Ref ${selector} not found. Run 'snapshot' to get fresh refs.` |
| 95 | ); |
| 96 | } |
| 97 | const count = await entry.locator.count(); |
| 98 | if (count === 0) { |
| 99 | throw new Error( |
| 100 | `Ref ${selector} (${entry.role} "${entry.name}") is stale — element no longer exists. ` + |
| 101 | `Run 'snapshot' for fresh refs.` |
| 102 | ); |
| 103 | } |
| 104 | return { locator: entry.locator }; |
| 105 | } |
| 106 | return { selector }; |
| 107 | } |
| 108 | |
| 109 | /** Get the ARIA role for a ref selector, or null for CSS selectors / unknown refs. */ |
| 110 | getRefRole(selector: string): string | null { |
no test coverage detected