Skip to content

BrunoMedley/Selenium-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Selenium + RestAssured Test Automation Framework

A comprehensive test automation framework built with Selenium WebDriver for frontend testing, RestAssured for API testing, TestNG for test execution, and Page Object Pattern for maintainable code structure.

Features

  • βœ… Selenium WebDriver - Frontend UI automation
  • βœ… RestAssured - API testing
  • βœ… TestNG - Test execution and reporting
  • βœ… Page Object Pattern - Maintainable and reusable page objects
  • βœ… Log4j2 - Comprehensive logging
  • βœ… Multi-Environment Support - Dev, Staging, Production configurations
  • βœ… WebDriverManager - Automatic browser driver management
  • βœ… Maven - Dependency management and build tool

Project Structure

.
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/
β”‚   β”‚   β”‚   └── com/automation/
β”‚   β”‚   β”‚       β”œβ”€β”€ base/              # Base test classes
β”‚   β”‚   β”‚       β”œβ”€β”€ pages/             # Page Object classes
β”‚   β”‚   β”‚       └── utils/             # Utility classes
β”‚   β”‚   └── resources/
β”‚   β”‚       β”œβ”€β”€ config/                # Environment properties
β”‚   β”‚       └── log4j2.xml            # Logging configuration
β”‚   └── test/
β”‚       └── java/
β”‚           └── com/automation/
β”‚               └── tests/
β”‚                   β”œβ”€β”€ api/           # API test classes
β”‚                   └── frontend/      # Frontend test classes
β”œβ”€β”€ logs/                              # Log files directory
β”œβ”€β”€ test-suites/                       # Test suite configurations
β”‚   β”œβ”€β”€ smoke-suite.xml               # Smoke test suite
β”‚   β”œβ”€β”€ regression-suite.xml          # Regression test suite
β”‚   β”œβ”€β”€ full-suite.xml                # Full test suite
β”‚   β”œβ”€β”€ api-suite.xml                 # API test suite
β”‚   └── frontend-suite.xml            # Frontend test suite
β”œβ”€β”€ pom.xml                            # Maven dependencies
β”œβ”€β”€ testng.xml                         # Default TestNG configuration
β”œβ”€β”€ run-tests.sh                       # Test runner script
└── README.md                          # This file

Prerequisites

  • Java 11 or higher
  • Maven 3.6 or higher
  • Chrome/Firefox/Edge browser installed

Setup Instructions

  1. Clone or download the project

  2. Install dependencies

    mvn clean install
  3. Configure environment properties

    • Edit src/main/resources/config/dev.properties
    • Edit src/main/resources/config/staging.properties
    • Edit src/main/resources/config/prod.properties
    • Update URLs, credentials, and other configuration values
  4. Create logs directory

    mkdir logs

Running Tests

Run all tests (default suite)

mvn test

Run specific test suite with environment parameter

Using Maven directly:

# Run smoke tests on dev environment
mvn test -DsuiteXmlFile=test-suites/smoke-suite.xml -Denvironment=dev

# Run regression tests on staging environment
mvn test -DsuiteXmlFile=test-suites/regression-suite.xml -Denvironment=staging

# Run full suite on production
mvn test -DsuiteXmlFile=test-suites/full-suite.xml -Denvironment=prod

# Run API tests only
mvn test -DsuiteXmlFile=test-suites/api-suite.xml -Denvironment=dev

# Run frontend tests only
mvn test -DsuiteXmlFile=test-suites/frontend-suite.xml -Denvironment=dev

Using the test runner script:

# Run smoke tests on dev (default environment)
./run-tests.sh smoke

# Run regression tests on staging
./run-tests.sh regression staging

# Run full suite on production
./run-tests.sh full prod

# Run API tests
./run-tests.sh api dev

# Run frontend tests
./run-tests.sh frontend staging

Available Test Suites

  1. smoke-suite.xml - Quick smoke tests for critical functionality

    • Runs: testValidLogin, testHomePageElements, testGetUser
    • Environment: dev (default)
  2. regression-suite.xml - Full regression test suite

    • Runs: All tests with regression group
    • Environment: staging (default)
  3. full-suite.xml - Complete test suite

    • Runs: All tests (frontend + API)
    • Environment: dev (default)
  4. api-suite.xml - API tests only

    • Runs: All API tests
    • Environment: dev (default)
  5. frontend-suite.xml - Frontend tests only

    • Runs: All frontend tests
    • Environment: dev (default)
  6. testng.xml - Default suite

    • Runs: All tests
    • Environment: dev (default)

Run specific test class

mvn test -Dtest=LoginPageTest

Run tests by groups

# Run only smoke tests
mvn test -Dgroups=smoke

# Run only regression tests
mvn test -Dgroups=regression

Run tests in parallel

All test suites are configured for parallel execution. Adjust thread-count in the suite XML files as needed.

Configuration

Environment Properties

Each environment has its own properties file:

  • dev.properties - Development environment
  • staging.properties - Staging environment
  • prod.properties - Production environment

Properties Available:

  • base.url - Frontend application URL
  • api.base.url - API base URL
  • browser - Browser to use (chrome, firefox, edge)
  • headless - Run browser in headless mode (true/false)
  • implicit.wait - Implicit wait time in seconds
  • explicit.wait - Explicit wait time in seconds
  • page.load.timeout - Page load timeout in seconds
  • api.timeout - API request timeout in milliseconds
  • username - Test username
  • password - Test password

Page Object Pattern

The framework uses Page Object Pattern for better maintainability:

  • BasePage - Base class with common methods
  • LoginPage - Login page object
  • HomePage - Home page object

Creating a New Page Object

  1. Create a new class extending BasePage
  2. Use @FindBy annotations for element locators
  3. Create methods for page actions

Example:

public class NewPage extends BasePage {
    @FindBy(id = "element-id")
    private WebElement element;
    
    public void performAction() {
        click(element);
    }
}

API Testing

The framework includes RestAssured for API testing:

  • ApiClient - Base API client with request/response specifications
  • BaseAPITest - Base class for API tests
  • UserAPITest - Example API test class

Example API Test

Response response = ApiClient.getRequestSpec()
    .when()
    .get("/users/1")
    .then()
    .extract()
    .response();

Logging

Logs are configured using Log4j2:

  • Console output for immediate feedback
  • File output in logs/automation.log
  • Automatic log rotation (daily and size-based)

Browser Support

The framework supports:

  • Chrome (default)
  • Firefox
  • Edge

Browser drivers are automatically managed by WebDriverManager.

Test Groups

Tests are organized into groups for flexible test execution:

  • smoke - Critical tests that verify basic functionality
  • regression - Comprehensive tests for full regression testing

Adding Test Groups

Add groups to your test methods:

@Test(priority = 1, description = "Test description", groups = {"smoke", "regression"})
public void testMethod() {
    // Test implementation
}

Test Suite Configuration

Each test suite XML file can:

  • Specify which tests to run (by class, method, or group)
  • Set default environment
  • Configure parallel execution
  • Set thread count for parallelization

Best Practices

  1. Page Object Pattern: Always use Page Objects for UI interactions
  2. Logging: Use logger for important actions and assertions
  3. Wait Strategies: Use explicit waits instead of Thread.sleep()
  4. Environment Configuration: Keep sensitive data in properties files
  5. Test Data: Externalize test data when possible
  6. Clean Code: Follow naming conventions and code organization
  7. Test Groups: Organize tests into groups (smoke, regression) for flexible execution
  8. Test Suites: Use appropriate test suites for different scenarios

Troubleshooting

Browser driver issues

WebDriverManager should handle this automatically. If issues persist:

  • Check internet connection
  • Manually download drivers and add to PATH

Properties file not found

  • Ensure properties files are in src/main/resources/config/
  • Check file names match environment parameter

Logs directory not found

  • Create logs directory in project root
  • Ensure write permissions

Contributing

  1. Follow the existing code structure
  2. Add appropriate logging
  3. Update documentation as needed
  4. Test your changes

License

This project is for educational and testing purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors