Basic E2E Test with Authentication
End-to-end test with authentication setup using accessibility selectors
import { test, expect } from '@playwright/test';
test.describe('Dashboard Tests', () => {
test.beforeEach(async ({ page }) => {
// Login before each test
await page.goto('http://localhost:3000/login');
await page.getByLabel('Email').fill('user@example.com');
await page.getByLabel('Password').fill('password123');
await page.getByRole('button', { name: 'Sign In' }).click();
await page.waitForURL('**/dashboard');
});
test('displays welcome message', async ({ page }) => {
const heading = page.getByRole('heading', { name: /welcome/i });
await expect(heading).toBeVisible();
});
test('loads user profile data', async ({ page }) => {
await page.getByRole('link', { name: 'Profile' }).click();
await expect(page.getByText('user@example.com')).toBeVisible();
});
});