When clicking an element that is blocked by a cookie banner or modal overlay, the error message incorrectly showed "Element not found or not visible" even though the element was found and visible. The issue was in toAIFriendlyError(): the check for "Timeout" was evaluated before "intercepts pointer events", causing the wrong error message to be returned. Changes: - Reorder error detection to check "intercepts pointer events" before "Timeout" - Improve error message to suggest dismissing modals/cookie banners - Export toAIFriendlyError for testing - Add focused tests for overlay blocking behavior Before: Element "@e4" not found or not visible. Run 'snapshot' to see current page elements. After: Element "@e4" is blocked by another element (likely a modal or overlay). Try dismissing any modals/cookie banners first. Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
40 lines
1.8 KiB
TypeScript
40 lines
1.8 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { toAIFriendlyError } from './actions.js';
|
|
|
|
describe('toAIFriendlyError', () => {
|
|
describe('element blocked by overlay', () => {
|
|
it('should detect intercepts pointer events even when Timeout is in message', () => {
|
|
// This is the exact error from Playwright when a cookie banner blocks an element
|
|
// Bug: Previously this was incorrectly reported as "not found or not visible"
|
|
const error = new Error(
|
|
'TimeoutError: locator.click: Timeout 10000ms exceeded.\n' +
|
|
'Call log:\n' +
|
|
" - waiting for getByRole('link', { name: 'Anmelden', exact: true }).first()\n" +
|
|
' - locator resolved to <a href="https://example.com/login">Anmelden</a>\n' +
|
|
' - attempting click action\n' +
|
|
' 2 x waiting for element to be visible, enabled and stable\n' +
|
|
' - element is visible, enabled and stable\n' +
|
|
' - scrolling into view if needed\n' +
|
|
' - done scrolling\n' +
|
|
' - <body class="font-sans antialiased">...</body> intercepts pointer events\n' +
|
|
' - retrying click action'
|
|
);
|
|
|
|
const result = toAIFriendlyError(error, '@e4');
|
|
|
|
// Must NOT say "not found" - the element WAS found
|
|
expect(result.message).not.toContain('not found');
|
|
// Must indicate the element is blocked
|
|
expect(result.message).toContain('blocked by another element');
|
|
expect(result.message).toContain('modal or overlay');
|
|
});
|
|
|
|
it('should suggest dismissing cookie banners', () => {
|
|
const error = new Error('<div class="cookie-overlay"> intercepts pointer events');
|
|
const result = toAIFriendlyError(error, '@e1');
|
|
|
|
expect(result.message).toContain('cookie banners');
|
|
});
|
|
});
|
|
});
|