A modern, robust test automation framework built with Playwright, Cucumber, and Java, following best practices and design patterns. Work in progress!
-
Page Object Model (POM) - Enhanced with a three-layer approach:
Component
- Contains element locators and basic element interactionsFunctions
- Contains business-level actionsState
- Contains state verification and assertions
-
Singleton Pattern
- Used in Configuration management
- Ensures single instance of test context per thread.
-
Factory Pattern
- Browser and page initialization
- Configuration management
-
Dependency Injection
- Using PicoContainer for Cucumber
- Automatic dependency management
- Improved test maintenance and readability
BasePage
- Abstract base class for all page objectsTestContext
- Thread-safe context managementConfiguration
- Centralized configuration managementHooks
- Test lifecycle management
- ✅ Thread-safe execution
- ✅ Parallel test execution support
- ✅ Scenario context storage
- ✅ Automatic screenshot capture on failure
- ✅ Configurable timeouts
- ✅ Environment-specific configuration
- ✅ HTML, JSON, and XML reporting
- ✅ Custom exception handling
- Java
- Playwright
- Cucumber (BDD)
- JUnit
- PicoContainer (Dependency Injection)
- Maven
-
Maintainability
- Clear separation of concerns
- Reusable components
- Centralized configuration
- Easy to extend and modify
-
Reliability
- Thread-safe execution
- Robust error handling
- Consistent timeout management
- Automatic cleanup of resources
-
Scalability
- Support for parallel execution
- Easy to add new features
- Modular architecture
- Environment-agnostic design
-
Readability
- BDD-style test scenarios
- Clear page object structure
- Self-documenting code
- Consistent naming conventions
-
Prerequisites
- Java 11 or higher - Maven
-
Running Tests
# Run all tests mvn clean test # Run with specific tags mvn test -Dcucumber.filter.tags="@smoke" # Run with specific environment mvn test -DbaseUrl=https://staging.ultimateqa.com
Reports are generated in target/cucumber-reports/
directory:
- HTML Report:
cucumber.html
- JSON Report:
cucumber.json
- XML Report:
cucumber.xml
Environment variables can be set through:
- System properties
- Configuration class
- Maven command line parameters
Example:
mvn test -DbaseUrl=https://staging.ultimateqa.com -Dbrowser=firefox -Dheadless=true
-
Page Objects
- Keep locators in Component classes
- Business logic in Functions classes
- State verification in State classes
-
Test Data
- Use TestContext for sharing data between steps
- Clear context after each scenario
- Use thread-safe storage methods
-
Error Handling
- Custom exceptions for better error reporting
- Automatic screenshot capture on failure
- Proper cleanup in teardown
-
Configuration
- Environment-specific settings
- Centralized configuration management
- Easy to override defaults
- Follow the existing design patterns
- Add appropriate unit tests
- Update documentation
- Follow code style guidelines
Now you can run the tests in several ways:
- Run all tests in headless mode:
npm test
- Run tests in headed mode (browser visible):
npm run test:headed
- Run tests with Playwright UI mode (interactive):
npm run test:ui
- Run tests in debug mode:
npm run test:debug
Let's try running the tests in headed mode so you can see what's happening: