Skip to content

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ΒΆ

  1. Clone the repository

    git clone <repository-url>
    cd fahmi-java-framework
    

  2. Install dependencies

    mvn clean install
    

  3. 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ΒΆ

mvn clean test
allure serve target/allure-results

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:

  1. Environment Setup

    • Java 19 with Maven caching
    • Chrome browser installation
    • Allure CLI setup
  2. Test Execution

    • Clean test runs with parallel execution
    • Environment variable support
    • Comprehensive logging
  3. Report Generation

    • Automatic Allure report generation
    • GitHub Pages deployment
    • Artifact preservation
  4. 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 BaseTests for standard UI tests
  • Page Objects: Implement page object pattern for maintainability
  • Test Data: Use parameterized tests for data-driven testing
  • Assertions: Use ValidationUtils for detailed validation reporting

Error HandlingΒΆ

  • Automatic Screenshots: Failure screenshots via ScreenshotTestWatcher
  • Retry Mechanisms: Built into SafeAction utilities
  • 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ΒΆ

# Increase Maven memory
export MAVEN_OPTS="-Xmx2048m -XX:MaxMetaspaceSize=512m"

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¢

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. 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

πŸ“„ 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! πŸŽ‰