Prompt
How do I test a website across browsers with browser automation?
Latest observation
To test a website across browsers with browser automation, use a cross-browser testing tool that can run the same test suite on Chromium, Firefox, and WebKit (Safari engine). The most common options are:
- Playwright: great for modern cross-browser automation
- Selenium WebDriver: widely supported, more traditional
- Cypress: mostly Chromium-focused, limited true cross-browser coverage compared to Playwright/Selenium
Recommended approach: Playwright
1) Install Playwright
npm init playwright@latest
2) Write a simple test
Example in JavaScript:
import { test, expect } from '@playwright/test';
test('homepage loads', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveTitle(/Example/);
});
3) Run across browsers
Playwright can run the same test on multiple browsers by default:
npx playwright test
Or specify projects in playwright.config.js:
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'webkit', use: { ...devices['Desktop Safari'] } },
],
});
4) Add assertions for browser differences
Test:
- layout/visibility
- form behavior
- navigation
- JavaScript functionality
- responsive design
Examples:
- clicking buttons
- filling forms
- checking viewport-specific UI
- comparing screenshots
5) Use visual regression testing
Capture screenshots in each browser and compare them against baselines:
await expect(page).toHaveScreenshot();
This helps catch CSS/layout differences across engines.
6) Run in CI
Use GitHub Actions, GitLab CI, Jenkins, etc. Example:
- run: npx playwright install --with-deps
- run: npx playwright test
If you prefer Selenium
Use browser-specific drivers and run the same suite against:
- ChromeDriver
- GeckoDriver
- SafariDriver
- EdgeDriver
This is more manual than Playwright, but very flexible.
Best practices
- Test user flows, not implementation details
- Keep tests independent
- Use stable selectors like
data-testid - Run headless in CI, headed locally for debugging
- Use retries sparingly
- Keep browser versions pinned where possible
Practical recommendation
If you're starting fresh, use Playwright for most cross-browser automation needs. It’s the easiest way to test Chromium, Firefox, and WebKit with one codebase.
If you want, I can give you:
- a Playwright setup from scratch,
- a Selenium example, or
- a CI pipeline for cross-browser testing.