A comprehensive web automation testing framework built with Playwright for Java, TestNG, and Extent Reports. This project demonstrates automated testing of the Sauce Demo application with modern testing practices.
- Playwright for Java: Modern web automation with excellent browser support
- TestNG Framework: Advanced testing framework with parallel execution
- Extent Reports: Beautiful HTML test reports with detailed analytics
- Log4j2 Logging: Comprehensive logging for debugging and monitoring
- Page Object Model: Maintainable and scalable test architecture
- Retry Mechanism: Automatic retry for failed test cases
- Multi-browser Support: Chrome, Firefox, and Safari support
- Parallel Execution: Configurable thread execution for faster test runs
- Java 21 or higher
- Maven 3.6 or higher
- Git
-
Clone the repository
git clone https://github.com/harichandra-github/playwrightAutomationProject.git cd playwrightAutomationProject -
Install Playwright browsers
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install" -
Verify installation
mvn clean compile
playwrightAutomationProject/
├── src/
│ ├── main/java/com/qa/saucedemo/
│ │ ├── constants/
│ │ │ └── AppConstants.java # Application constants
│ │ ├── factory/
│ │ │ └── PlaywrightFactory.java # Browser factory
│ │ ├── listeners/
│ │ │ ├── ExtentManager.java # Extent reports manager
│ │ │ ├── ExtentTestManager.java # Test management
│ │ │ ├── RetryFailed.java # Retry logic
│ │ │ ├── RetryListener.java # Retry listener
│ │ │ └── TestListener.java # Test lifecycle events
│ │ ├── logger/
│ │ │ └── Log.java # Logging utilities
│ │ ├── pages/
│ │ │ ├── CartPage.java # Cart page object
│ │ │ ├── HomePage.java # Home page object
│ │ │ ├── LoginPage.java # Login page object
│ │ │ └── ProductPage.java # Product page object
│ │ └── utilities/
│ │ └── CommonFunctions.java # Common utility functions
│ └── test/
│ ├── java/com/qa/saucedemo/
│ │ ├── base/
│ │ │ └── BaseTest.java # Base test class
│ │ └── tests/
│ │ └── LoginTest.java # Login test scenarios
│ └── resources/
│ ├── config/
│ │ └── config.properties # Configuration properties
│ ├── log4j2.xml # Logging configuration
│ └── runners/
│ └── testng.xml # TestNG suite configuration
├── Reports/ # Generated test reports
├── logs/ # Application logs
└── pom.xml # Maven dependencies
Edit src/test/resources/config/config.properties:
# Browser settings
browser=firefox # chrome, firefox, safari
headless=false # true for headless mode
# Application settings
url=https://www.saucedemo.com/
username=standard_user
password=secret_sauce
# Test settings
retryCount=3 # Number of retry attempts for failed testsThe test suite is configured in src/test/resources/runners/testng.xml:
- Parallel execution with 5 threads
- Extent reports and retry listeners enabled
- Test classes included in the suite
mvn clean testmvn test -Dtest=LoginTestmvn test -Dtest=LoginTest#loginToAppmvn test -DsuiteXmlFile=src/test/resources/runners/testng.xmlmvn test -DthreadCount=3After test execution, detailed HTML reports are generated in the Reports/TestReport/ directory. Each report includes:
- Test execution summary
- Pass/fail statistics
- Screenshots for failed tests
- Detailed test logs
- System information
Application logs are stored in logs/app.log with different log levels:
- INFO: General information
- ERROR: Error messages
- DEBUG: Debug information
- WARN: Warning messages
The project follows the Page Object Model pattern:
- LoginPage: Handles login functionality
- HomePage: Manages home page interactions
- CartPage: Cart-related operations
- ProductPage: Product page interactions
PlaywrightFactory manages browser initialization and configuration:
- Multi-browser support
- Configurable browser options
- Context and page management
- ExtentManager: Generates comprehensive test reports
- RetryListener: Automatically retries failed tests
- TestListener: Handles test lifecycle events
Utility functions for:
- Timestamp generation
- Configuration loading
- Common operations
- Valid login with standard user
- Navigation to home page
- Page title and URL verification
- Product sorting and filtering
- Add/remove items from cart
- Checkout process
- User menu interactions
- Page Object Model: Maintains separation between test logic and page interactions
- Configuration Management: Externalized configuration for different environments
- Logging: Comprehensive logging for debugging and monitoring
- Retry Mechanism: Improves test stability with automatic retries
- Parallel Execution: Faster test execution with configurable threads
- Extent Reports: Professional test reporting with detailed analytics
-
Browser not found
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install" -
Java version issues
- Ensure Java 21+ is installed
- Check JAVA_HOME environment variable
-
Maven dependencies
mvn clean install
Enable debug logging by modifying log4j2.xml:
<Logger name="com.qa.saucedemo" level="DEBUG"/>Harichandra Chaudhari
- GitHub: @harichandra-github
- Linkedin: @harichandra-chaudhari
- Email: harichandrachaudhari21@gmail.com
- Phone: +91-866-900-9231
- Playwright - Modern web automation
- TestNG - Testing framework
- Extent Reports - Test reporting
- Sauce Demo - Test application
**Happy Testing! **