- Enhanced documentation with selector stability best practices - Added recommendations for resilient testing and deployment - Created verify-selectors.sh script to validate critical selectors pre-deployment - Added pre-deploy-validation.sh for comprehensive environment validation - Improved troubleshooting section with specific recommendations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
6 KiB
E2E Testing Strategy for HVAC Community Events
This document outlines the testing strategy and implementation details for the E2E test suite, with a focus on certificate functionality testing.
Testing Architecture
1. Page Object Model (POM)
Our tests follow the Page Object Model pattern, which abstracts UI interactions into page-specific classes:
- BasePage.ts: Base class with common methods for all pages
- LoginPage.ts: Handles user authentication
- DashboardPage.ts: Interactions with the main dashboard
- CertificatePage.ts: Certificate generation and management functionality
- Additional page objects for other key pages
This approach provides:
- Reusable code for common UI interactions
- Centralized selectors for easier maintenance
- Better abstraction of implementation details
2. Test Organization
Tests are organized by feature area:
- certificate-generation.test.ts: Tests for generating certificates
- certificate-management.test.ts: Tests for certificate management operations
- optimized-certificate-tests.ts: Streamlined tests focused on specific features
3. Configuration and Utilities
- Config.ts: Centralized configuration parameters
- VerbosityController.ts: Controls logging and screenshot behavior
- playwright.config.ts: Playwright test runner configuration
Testing Challenges and Solutions
Multiple Playwright Versions
Problem: Multiple versions of Playwright and @playwright/test causing conflicts
Solution:
- Pin dependency versions in package.json
- Update to the latest stable version
- Remove duplicate dependencies
Configuration Issues
Problem: Complex configuration with dependencies that may not be properly initialized
Solution:
- Simplified configuration focusing on reliability
- Reduced dependencies on external utilities
- Clear separation of configuration and test code
Test Independence
Problem: Tests depending on global state or other tests
Solution:
- Self-contained tests that set up their own data
- Explicit cleanup of test data
- Clear test boundaries and responsibilities
Certificate Testing Strategy
1. Data Setup
For certificate testing, we create:
- Test events with known properties
- Test attendees with varied properties
- Checked-in status for some attendees
- Test certificates with different states (emailed, revoked)
2. Feature Testing
Our certificate tests verify:
- Certificate generation for checked-in attendees
- Certificate viewing functionality
- Certificate emailing operations
- Certificate revocation operations
- Certificate filtering (by event, attendee, status)
3. Attendee Search Testing
The attendee search feature is tested with multiple patterns:
- Full name search (e.g., "Ben Tester")
- Partial name search (e.g., "Ben" or "Smith")
- Full email search (e.g., "ben@tealmaker.com")
- Partial email search (e.g., "@gmail.com")
- Case-insensitive matching
Best Practices
-
Test Independence:
- Each test should create its own test data
- Tests should not depend on the state from other tests
- Clean up test data when possible
-
Explicit Waits:
- Use explicit waits rather than fixed timeouts
- Wait for specific elements/conditions, not fixed times
- Use appropriate timeouts for WordPress's slower operations
-
Error Handling:
- Implement proper error handling in tests
- Use try/catch blocks for potentially unstable operations
- Take screenshots on failures for easier debugging
-
Selector Stability:
- Use CSS selectors that are less likely to change
- Prefer attribute selectors (e.g.,
input[name="log"]) over ID selectors (e.g.,#user_login) - Use multiple selector strategies for critical elements with fallback mechanisms
- Implement robust error detection with multiple selector checks
- Centralize selectors in page objects for easier maintenance
- Regularly validate selectors with debug tests when UI changes occur
-
Descriptive Naming:
- Use clear, descriptive test names
- Name page object methods according to user actions
- Add comments for complex operations
Optimized Testing Workflow
-
Initial Setup:
# Install dependencies npm install # Install Playwright browsers npx playwright install -
Running Certificate Tests:
# Run optimized certificate tests npx playwright test tests/e2e/optimized-certificate-tests.ts --headed # Run with debugging npx playwright test tests/e2e/optimized-certificate-tests.ts --headed --debug -
Visual Verification:
- Screenshots are taken at key points during test execution
- Visual verification can be done by examining the screenshots
- The HTML report provides a visual overview of test results
Future Improvements
-
Data Generation:
- Create a more robust test data generator
- Support for creating varied test scenarios
- Better cleanup of test data
-
Test Coverage:
- Expand tests to cover more edge cases
- Add tests for error handling
- Include mobile viewport testing
-
Performance Optimization:
- Profile and optimize test execution time
- Reduce unnecessary waits and operations
- Improve parallel test execution where possible
-
Reporting:
- Enhanced test reporting with more details
- Integration with CI/CD systems
- Slack/email notifications for test failures
-
Selector Resilience:
- Debug scripts to verify selectors before running tests
- Regular selector validation as part of CI pipeline
- Automated UI change detection with selector recommendations
- Selector versioning to handle multiple WordPress theme versions
-
Deployment Resilience:
- Pre-deployment validation of critical selectors
- Canary deployments with automatic rollback on test failures
- Health check scripts for validating WordPress plugin environment
- Automated recovery procedures for common failure scenarios
- Snapshot testing for detecting unintended UI changes