Writing E2E tests
Test Structure
const { test, expect } = require('@playwright/test');
test('description of test scenario', async ({ page }) => {
// Test implementation
});
// Group related tests
test.describe('Feature Group', () => {
test('specific test case', async ({ page }) => {
// Test implementation
});
});Locating Elements
// By CSS Selector
await page.locator('.login-button');
// By Text
await page.getByText('Submit');
// By Role
await page.getByRole('button', { name: 'Login' });
// By Test ID (Recommended for stability)
await page.getByTestId('login-submit');Best Practices for Element Locators
Interactions
Assertions
Page Object Model
Handling Async Operations
Common Scenarios
Last updated
Was this helpful?