Overview
Our e2e test suite uses Playwright to ensure critical user workflows function correctly across the application. The tests are organized using the Page Object Model pattern to maintain clean, reusable, and maintainable test code. This playbook outlines the structure, conventions, and best practices for writing e2e tests.Project Structure
Page Object Model Pattern
Base Page Structure
All page objects extend theBasePage
class and follow a consistent structure:
Page Object Guidelines
❌ Don’t do
✅ Do
Test Organization
Test File Structure
Test files should be organized by feature or workflow:Test Naming Conventions
- Use descriptive test names that explain the expected behavior
- Follow the pattern:
should [action] [expected result]
- Include context when relevant
Configuration Management
Environment Configuration
Use the centralized config utility to handle different environments:Environment Variables
Required environment variables for CI/CD:E2E_INSTANCE_URL
: Target application URLE2E_EMAIL
: Test user emailE2E_PASSWORD
: Test user password
Writing Effective Tests
Test Structure
Follow this pattern for comprehensive tests:Wait Strategies
Use appropriate wait strategies instead of fixed timeouts:Error Handling
Implement proper error handling and cleanup:Best Practices
Element Selection
Prefer semantic selectors over CSS selectors:Test Data Management
Use dynamic test data to avoid conflicts:Assertions
Use meaningful assertions that verify business logic:Running Tests
Local Development & Debugging with Checkly
We use Checkly to run and debug E2E tests. Checkly provides video recordings for each test run, making it easy to debug failures.- Test results, including video recordings, are available in the Checkly dashboard.
- You can debug failed tests by reviewing the video and logs provided by Checkly.
Deploying Tests
Manual deployment is rarely needed, but you can trigger it with:Tests are deployed to Checkly automatically after successful test runs in the CI pipeline.
Debugging Tests
1. Checkly Videos and Reports
When running tests with Checkly, each test execution is recorded and detailed reports are generated. This is the fastest way to debug failures:- Video recordings: Watch the exact browser session for any test run.
- Step-by-step logs: Review detailed logs and screenshots for each test step.
- Access: Open the Checkly dashboard and navigate to the relevant test run to view videos and reports.
2. VSCode Extension
For the best local debugging experience, install the Playwright Test for VSCode extension:- Open VSCode Extensions (Ctrl+Shift+X)
- Search for “Playwright Test for VSCode”
- Install the extension by Microsoft
- Debug tests directly in VSCode with breakpoints
- Step-through test execution
- View test results and traces in the Test Explorer
- Auto-completion for Playwright APIs
- Integrated test runner
3. Debugging Tips
- Use Checkly dashboard: Review videos and logs for failed tests.
- Use VSCode Extension: Set breakpoints directly in your test files.
- Step Through: Use F10 (step over) and F11 (step into) in debug mode.
- Inspect Elements: Use
await page.pause()
to pause execution and inspect the page. - Console Logs: Add
console.log()
statements to track execution flow. - Manual Screenshots: Take screenshots at critical points for visual debugging.
Common Patterns
Authentication Flow
Flow Creation and Testing
API Integration Testing
Maintenance Guidelines
Updating Selectors
When UI changes occur:- Update page object getters with new selectors
- Test the changes locally
- Update related tests if necessary
- Ensure all tests pass before merging
Adding New Tests
- Create or update relevant page objects
- Write test scenarios in appropriate spec files
- Follow the established patterns and conventions
- Add proper error handling and cleanup
- Test locally before submitting
Performance Considerations
- Keep tests focused and avoid unnecessary steps
- Use appropriate timeouts (not too short, not too long)
- Clean up test data to avoid conflicts
- Group related tests in the same describe block