Created
July 2, 2025 10:57
-
-
Save observethenoyes/b7c9d4eef1388cb59e35b86c38abd7e0 to your computer and use it in GitHub Desktop.
Detect console errors with Playwright
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { test, expect } from '@playwright/test'; | |
| test.describe('Console error detection', () => { | |
| test('should have no console errors on page load', async ({ page }) => { | |
| const consoleErrors: string[] = []; | |
| // Listen for console events and collect error messages | |
| page.on('console', msg => { | |
| if (msg.type() === 'error') { | |
| consoleErrors.push(msg.text()); | |
| } | |
| }); | |
| // Navigate to your target page | |
| await page.goto('https://checklyhq.com'); | |
| // You can perform additional interactions here if needed | |
| // Assert that no console errors were captured | |
| expect(consoleErrors, | |
| `Found console errors:\n${consoleErrors.join('\n')}` | |
| ).toHaveLength(0); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment