Skip to content

akashgkrishna/BookCart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BookCart Test Automation Framework

Java Selenium TestNG Logback Allure Lombok

A Selenium-based, cross-browser test automation framework for the BookCart web application, supporting multiple environments, data-driven testing, reporting with Allure and custom logging.

Table of Contents

Features

  • Environment Config: Easily switch between QA, Staging, and Production via config.properties and system properties.
  • Driver Management: Centralized driver handling.
  • Page Object Model (POM): Structured POM with separate packages for base pages, common components, and specialized pages.
  • Test Flow Abstraction: Business logic encapsulated in flow classes (e.g., LoginFlow, UserRegistrationFlow).
  • Data-Driven Testing: Centralized data generation with TestNG data providers for unique test runs.
  • Allure Reporting: Auto-attached step annotations, failure screenshots, test descriptions, severity levels, and TMS links.
  • Custom Logging: SLF4J/Logback with custom logger for clear, secure logs.
  • Lombok Integration: Clean models with @Builder.
  • AspectJ Weaving: Runtime instrumentation for enhanced reporting.
  • Smart Waits: Mix of explicit waits and utility methods.
  • Headless Execution: Configurable via config.properties.

Prerequisites

  • Java 22 JDK
  • Maven 3.6+
  • Chrome Browser (latest)
  • IDE (IntelliJ/Eclipse/VSCode)

Installation

  1. Clone the repository:
    git clone git@github.com:akashgkrishna/BookCart.git
  2. Build the project:
    mvn clean install

Configuration

Environment Setup: (config.properties)

  • Edit src/main/resources/config.properties to modify environment URLs
  • Supported environments: QA, Prod, Staging
  • Default environment: QA
# Environment URLs
qa.url=https://bookcart.azurewebsites.net/
staging.url=https://staging-bookcart.azurewebsites.net/
prod.url=https://prod-bookcart.azurewebsites.net/

# Credentials
qa.username=qa_user
qa.password=qa_password
staging.username=staging_user
staging.password=staging_password
prod.username=prod_user
prod.password=prod_password

Log Configuration: (logback.xml)

<!-- Configure logging patterns and output locations -->
<root level="trace">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
</root>

Browser setup:

  • Currently, supports (Chrome, Firefox, Safari and Edge)
  • Chrome is the default browser .
  • If you want other drivers just add the appropriate WebDriver instance in DriverManager class
# Browser configuration  
browser=chrome  
headless=true

Safari Browser setup:

Safari's settings need to be adjusted to allow automation. Follow these steps:

  1. Enable the Develop Menu:
    Open Safari and go to Safari > Preferences > Advanced. Then, check the box that says "Show Develop menu in menu bar".

  2. Allow Remote Automation:
    Once the Develop menu is visible, click on Develop in the menu bar and select "Allow Remote Automation". This setting permits WebDriver to control Safari.

  3. Restart Safari:
    After enabling the setting, close Safari and re-launch it to ensure the changes take effect.

These adjustments should allow SafariDriver to create a new session successfully.

Lombok setup

Verify Lombok is enabled in your IDE. Without Lombok processing, none of the builder methods or getters (provided by @Getter and @Builder) are generated.

1. Add Lombok Dependency:
Ensure that your pom.xml contains the Lombok dependency. For example:

<dependency> 
	<groupId>org.projectlombok</groupId>
	<artifactId>lombok</artifactId> 
	<version>1.18.24</version> 
	<scope>provided</scope> 
</dependency>

2. Enable Annotation Processing:

  • If you’re using an IDE like IntelliJ IDEA or Eclipse, make sure that annotation processing is enabled.
    • For Maven, the compiler plugin should pick up Lombok annotations if the dependency is correctly added.

3. Clean and Rebuild:
After adjusting your configuration, perform a clean build (e.g., mvn clean compile) to verify that Lombok generates the expected methods.

Allure Configuration (allure.properties)

allure.results.directory=target/allure-results

Error Messages (error-messages.properties)

invalid.username=User Name is not available
invalid.password=Password requirements not met

TestNG Suite (testng.xml)

<listeners>
    <listener class-name="io.qameta.allure.testng.AllureTestNg"/>
</listeners>

Execution

Default (QA Environment):

mvn test

Specific Environment:

mvn test -Denv=prod

Supported Environments:

  • -Denv=qa (default)
  • -Denv=staging
  • -Denv=prod

Generate Allure Report

mvn allure:serve

Logging

Usage in Tests:

public class BasicTest extends BaseTest {
    @Test
    public void exampleTest() {
        logger.info("Using credentials: {}", username);
        logger.error("Validation failed!");
    }
}

Log Outputs:

14:23:45 INFO  [TestNG] o.b.BasicTest - Using credentials: test01
14:23:46 ERROR [TestNG] o.b.BasicTest - Validation failed!

Project Structure

├── LICENSE                           // License information (e.g., MIT License)
├── README.md                         // Project documentation and usage instructions
├── pom.xml                           // Maven configuration with dependencies and build plugins
└── src
    ├── main
    │   ├── java/org/bookcart/         // Main application code
    │   │   ├── base/                  // Base test classes (e.g., BaseTest.java for setup/teardown)
    │   │   ├── data/                  // Test data factories (e.g., UserDataFactory.java)
    │   │   ├── driver/                // WebDriver management (e.g., DriverManager.java)
    │   │   ├── flows/                 // Business logic flows (e.g., LoginFlow.java, UserRegistrationFlow.java)
    │   │   ├── model/                 // Data models (e.g., User.java)
    │   │   ├── pages/                 // Page Object Model classes (e.g., LoginPage.java, RegisterPage.java)
    │   │   └── util/                  // Utility classes for various common functionalities:
    │   │       ├── ConfigManager.java         // Loads and manages configuration properties
    │   │       ├── CredentialsManager.java    // Retrieves user credentials based on the environment
    │   │       ├── MessageUtils.java          // Handles common messages (e.g., error/info messages)
    │   │       ├── ScreenshotUtils.java       // Captures screenshots for reporting, especially on failures
    │   │       ├── WaitUtils.java             // Provides explicit wait methods for synchronizing tests
    │   │       └── logging/                   // Custom logging utilities:
    │   │           ├── CustomLogger.java      // Wrapper for logging functionality (using SLF4J/Logback)
    │   │           └── LogManager.java        // Factory for instantiating and managing loggers
    │   └── resources/                 // Application configuration files
    │       ├── config.properties      // Environment URLs, credentials, and other settings
    │       └── logback.xml            // Logging configuration (patterns, output locations)
    └── test
        ├── java/org/bookcart/         // Test code
        │   ├── login/                 // Login-related test classes:
        │   ├── providers/             // Data providers for tests:
        │   │   └── UserDataProviders.java   // Supplies dynamic test data for user-related tests
        │   └── userregistration/      // User registration test
        └── resources/                 // Test configuration files
            ├── allure.properties      // Configuration for Allure reporting
            ├── error-messages.properties  // Common error messages used in tests
            └── testng.xml           // TestNG suite configuration for test execution



Best Practices

Logger Usage

// Good
logger.info("Loading page: {}", url);

// Avoid
System.out.println("Loading page: " + url);

Environment Isolation

# Never commit production credentials
# Keep sensitive data in environment variables

Allure Reporting

Add the necessary Annotations in test Example:

@Test(dataProviderClass = UserDataProviders.class,  
        dataProvider = "invalidRegistrationData")  
@Description("Verify that registration fails when user enters existing username")  
@TmsLink("CEL-TC-46")  
@Severity(SeverityLevel.CRITICAL)

Add proper Step when needed Example:

@Step("Entering Credentials")  
public void enterCredentials(String username, String password) {  
    sendKeys(username, usernameTextField);  
    sendKeys(password, passwordTextField);  
}

Lombok Models

@Getter
@Builder
public class User {
    private final String username;
    private final String password;
}

Data-Driven Testing

@DataProvider
public Object[][] invalidLogins() {
    return new Object[][]{
            {"invalidUser", "wrongPass"},
            {"lockedUser", "secret123"}
    };
}

Future Roadmap

  • Add BrowserStack Integration
  • Create CI/CD Pipeline
  • Grouping Tests
  • Parallel Testing -TestNG parallel test runs
  • Docker Support - Containerized test execution

Report Issues

License

This project is licensed under the MIT License

About

A Selenium-based test automation framework for the BookCart web application

Topics

Resources

License

Stars

Watchers

Forks

Languages