Skip to content

Commit 36f4e07

Browse files
fix(server): preview automation reports ambiguous selectors instead of calling them invalid (pingdotgg#34205)
1 parent ab9df1d commit 36f4e07

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎apps/server/src/preview/ServerBrowser.test.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function makeContext(onClose?: (context: BrowserContext) => void, initialUrl = "
219219
interactiveElements: [],
220220
})),
221221
ariaSnapshot: vi.fn(async () => '- button "delete" [ref=e1]'),
222-
locator: vi.fn(() => {
222+
locator: vi.fn((): unknown => {
223223
throw new Error("Unexpected locator action");
224224
}),
225225
isClosed: () => closed,
@@ -994,6 +994,40 @@ it.live(
994994
).pipe(Effect.provide(layer)),
995995
);
996996

997+
it.live(
998+
"reports a valid CSS selector that matches several elements as ambiguous, not invalid",
999+
() =>
1000+
Effect.scoped(
1001+
Effect.gen(function* () {
1002+
const { broker, tabId } = yield* ready;
1003+
const strict = new Error(
1004+
"locator.scrollIntoViewIfNeeded: Error: strict mode violation: locator('button[aria-label=\\'Permissions: Full access\\']') resolved to 2 elements:",
1005+
);
1006+
contexts[0]!.page.locator.mockImplementation(
1007+
() =>
1008+
new Proxy(
1009+
{},
1010+
{
1011+
get: () => async () => {
1012+
throw strict;
1013+
},
1014+
},
1015+
),
1016+
);
1017+
const failure = yield* broker
1018+
.invoke<void>({
1019+
scope,
1020+
tabId,
1021+
operation: "click",
1022+
input: { selector: "button[aria-label='Permissions: Full access']", timeoutMs: 1_000 },
1023+
})
1024+
.pipe(Effect.flip);
1025+
expect(failure.message).not.toMatch(/invalid selector/);
1026+
expect(failure.message).toMatch(/2 elements/);
1027+
}),
1028+
).pipe(Effect.provide(layer)),
1029+
);
1030+
9971031
it.live("reports a pending dialog without evaluating the page and resolves it explicitly", () =>
9981032
Effect.scoped(
9991033
Effect.gen(function* () {

‎apps/server/src/preview/ServerBrowserPage.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ export const toOperationError = (
6464
detail: timeoutMs === undefined ? undefined : { timeoutMs },
6565
});
6666
}
67-
if (
68-
/while parsing selector|Unknown engine|Unexpected token|strict mode violation/i.test(message)
69-
) {
67+
if (/while parsing selector|Unknown engine|Unexpected token/i.test(message)) {
7068
return new ServerBrowserOperationError({
7169
tag: "PreviewAutomationInvalidSelectorError",
7270
message: firstLine,

0 commit comments

Comments
 (0)