Java Automation FrameworkΒΆ
A comprehensive test automation framework built with Java, Selenium WebDriver, REST Assured, JUnit 5, and Allure reporting. This framework supports both UI and API testing with advanced features like parallel execution, cross-browser testing, and detailed reporting.
π FeaturesΒΆ
Core CapabilitiesΒΆ
- UI Testing: Selenium WebDriver with cross-browser support
- API Testing: REST Assured for comprehensive API validation
- Parallel Execution: JUnit 5 parallel test execution
- Reporting: Allure reports with screenshots and detailed logs
- Cross-Browser: Chrome, Firefox, Edge, Safari, and IE support
- CI/CD Ready: GitHub Actions integration with automated report deployment
Advanced FeaturesΒΆ
- Event-Driven Logging: Comprehensive WebDriver event reporting
- Safe Actions: Enhanced element interactions with highlighting and scrolling
- Screenshot Management: Automatic failure screenshots with Allure integration
- Validation Utilities: Flexible validation framework with detailed reporting
- Configuration Management: Environment-based configuration support
π Framework MetricsΒΆ
- Languages: Java 19
- Test Framework: JUnit 5
- UI Automation: Selenium WebDriver 4.35.0
- API Testing: REST Assured 5.5.5
- Reporting: Allure 2.29.1
- Build Tool: Maven 3.14.0
- CI/CD: GitHub Actions
- Browsers Supported: Chrome, Firefox, Edge, Safari, IE
π Project StructureΒΆ
fahmi-java-framework/
βββ src/
β βββ main/java/
β β βββ config/
β β β βββ ConfigLoader.java # Configuration loader
β β β βββ TestConfig.java # Test configuration constants
β β βββ utils/
β β βββ EventReporter.java # WebDriver event logging
β β βββ SafeAction.java # Enhanced element interactions
β β βββ ScreenshotHandler.java # Screenshot management
β βββ test/java/
β β βββ base/
β β β βββ BaseTests.java # Base test class
β β β βββ ScreenshotCapable.java # Screenshot interface
β β β βββ ScreenshotTestWatcher.java # Test failure handler
β β βββ experimental/
β β β βββ PortfolioTest.java # Portfolio site test
β β βββ utils/
β β βββ CrossBrowser.java # Browser management
β β βββ ValidationUtils.java # Validation framework
β βββ main/resources/
β βββ dev.properties # Environment configuration
βββ .github/workflows/
β βββ ci.yml # CI/CD pipeline
βββ pom.xml # Maven dependencies
βββ README.md # This file
π οΈ Technologies & DependenciesΒΆ
Core TechnologiesΒΆ
- Java 19: Programming language
- Maven: Dependency management and build tool
- JUnit 5: Testing framework with parallel execution support
- Selenium WebDriver 4.35.0: UI automation
- REST Assured 5.5.5: API testing
- Allure 2.29.1: Test reporting and visualization
Key DependenciesΒΆ
- WebDriverManager 6.1.0: Automatic driver management
- Jackson 2.19.2: JSON processing
- Apache Commons: Utility libraries
- AssertJ 3.27.3: Fluent assertions
- Hamcrest 3.0: Matchers for testing
- Lombok 1.18.30: Boilerplate code reduction
π¦ Getting StartedΒΆ
PrerequisitesΒΆ
- Java 19 or higher
- Maven 3.6+
- Chrome browser (for default execution)
- Allure CLI (optional, for local report generation)
InstallationΒΆ
-
Clone the repository
-
Install dependencies
-
Configure environment (optional)
Edit src/main/resources/dev.properties:
PROJECT_DIR=C:\\path\\to\\your\\project
BASE_URL_DEV=https://your-test-site.com
GENERATE_ALLURE_HTML_REPORT=allure generate --single-file target/allure-results -o target/allure-report --clean
Running TestsΒΆ
Basic Test ExecutionΒΆ
# Run all tests
mvn clean test
# Run specific test class
mvn clean test -Dtest=PortfolioTest
# Run with specific browser
mvn clean test -Dbrowser=firefox
# Run in headless mode (CI environment)
mvn clean test -DHEADLESS=true
Parallel ExecutionΒΆ
Tests are configured to run in parallel by default. Configuration in src/test/resources/junit-platform.properties:
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.classes.default=concurrent
π Test ReportingΒΆ
Allure ReportsΒΆ
The framework automatically generates Allure reports with:
- Test execution results with pass/fail status
- Screenshots for failed tests
- Step-by-step execution details
- API request/response logs
- Environment information
Generate Local ReportΒΆ
View Reports in CIΒΆ
Reports are automatically deployed to GitHub Pages after each CI run. Access via:
https://<username>.github.io/<repository-name>/
π Cross-Browser SupportΒΆ
Supported BrowsersΒΆ
// Chrome (default)
WebDriver driver = CrossBrowser.getDriver("chrome");
// Firefox
WebDriver driver = CrossBrowser.getDriver("firefox");
// Edge
WebDriver driver = CrossBrowser.getDriver("edge");
// Safari (macOS only)
WebDriver driver = CrossBrowser.getDriver("safari");
// Headless Chrome (CI/CD)
WebDriver driver = CrossBrowser.getHeadlessChromeDriver();
Browser ConfigurationΒΆ
Each browser includes optimized settings:
- Chrome: Headless support, incognito mode, automation flags
- Firefox: Private browsing, notification blocking
- Edge: InPrivate mode, automation compatibility
- Safari: macOS-specific configurations
π§ Framework ComponentsΒΆ
SafeAction UtilityΒΆ
Enhanced element interactions with automatic retry and highlighting:
SafeAction safeAction = new SafeAction(driver);
// Safe clicking with scroll and highlight
safeAction.safeClick(By.id("submitButton"));
// Safe text input with validation
safeAction.safeInput(By.id("username"), "testuser");
// Dropdown selection
safeAction.selectFromDropdown(By.id("country"), "United States");
// Wait for elements with highlighting
safeAction.waitForElementToBeVisible(By.className("loading"));
Validation FrameworkΒΆ
Flexible validation system with detailed reporting:
ValidationUtils validator = new ValidationUtils(driver, "TestClassName");
// Different assertion types
validator.assertEquals("Login Title", "Expected Title", actualTitle);
validator.assertNotNull("User Profile", userProfile);
validator.assertTrue("Terms Accepted", isTermsChecked);
// Check all validations at test end
validator.checkValidationResults(); // Fails test if any validation failed
// OR
validator.printValidationSummary(); // Just prints summary
Screenshot ManagementΒΆ
Automatic screenshot capture for failures and manual screenshots:
ScreenshotHandler screenshot = new ScreenshotHandler(driver, "TestClass");
// Automatic failure screenshots (via ScreenshotTestWatcher)
// Manual screenshots
screenshot.takeFullPageScreenshot("login-page");
screenshot.attachScreenshotToAllure("Step 1 - Login Form");
// Highlighted element screenshots
screenshot.takeHighlightedElementScreenshot(By.id("error-message"), "error-state");
π CI/CD PipelineΒΆ
GitHub Actions WorkflowΒΆ
The framework includes a complete CI/CD pipeline (.github/workflows/ci.yml) that:
-
Environment Setup
- Java 19 with Maven caching
- Chrome browser installation
- Allure CLI setup
-
Test Execution
- Clean test runs with parallel execution
- Environment variable support
- Comprehensive logging
-
Report Generation
- Automatic Allure report generation
- GitHub Pages deployment
- Artifact preservation
-
Features
- Runs on every push to main branch
- Parallel job execution
- Detailed logging and error handling
- Automatic cleanup
Pipeline StatusΒΆ
# Trigger on main branch push
on:
push:
branches: [main]
# Parallel execution with 2 threads
parallel: classes
threadCount: 2
π― Best PracticesΒΆ
Test OrganizationΒΆ
- Base Classes: Extend
BaseTestsfor standard UI tests - Page Objects: Implement page object pattern for maintainability
- Test Data: Use parameterized tests for data-driven testing
- Assertions: Use
ValidationUtilsfor detailed validation reporting
Error HandlingΒΆ
- Automatic Screenshots: Failure screenshots via
ScreenshotTestWatcher - Retry Mechanisms: Built into
SafeActionutilities - Graceful Degradation: Cross-browser fallbacks
- Detailed Logging: Event-driven logging for debugging
PerformanceΒΆ
- Parallel Execution: JUnit 5 parallel test execution
- Driver Management: Automatic WebDriver lifecycle management
- Resource Cleanup: Proper driver cleanup after tests
- Caching: Maven dependency caching in CI
π TroubleshootingΒΆ
Common IssuesΒΆ
WebDriver IssuesΒΆ
# Clear WebDriver cache
mvn clean test -Dwdm.clearCache=true
# Force driver update
mvn clean test -Dwdm.forceCache=false
Memory IssuesΒΆ
Parallel Execution IssuesΒΆ
# Reduce parallelism in junit-platform.properties
junit.jupiter.execution.parallel.config.fixed.parallelism=1
Debug ModeΒΆ
Enable detailed logging by modifying the EventReporter configuration:
EventReporter listener = new EventReporter(
true, // logNavigation
true, // logElementInteractions
true // logDriverActions
);
π€ ContributingΒΆ
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
Development GuidelinesΒΆ
- Follow existing code style and patterns
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
π Quick LinksΒΆ
- Framework Repository: https://github.com/fahmi-wiradika/java-automation
- Live Test Results: https://fahmi-wiradika.github.io/java-automation
π LicenseΒΆ
This project is licensed under the Apache 2.0 License.
π SupportΒΆ
For questions and support:
- Issues: Create GitHub issues for bugs and feature requests
- Documentation: Check existing tests for usage examples
- Allure Reports: Review generated reports for test execution details
Happy Testing! π