Skip to content

A comprehensive guide to Java unit testing and ATDD with Selenium WebDriver and LambdaTest. Features cross-browser testing, parallel execution, Cucumber BDD, and professional logging for both unit tests and acceptance test automation.

Notifications You must be signed in to change notification settings

tutorials-coder/ATDD-testing-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ATDD Guide with LambdaTest E-Commerce

This project demonstrates Acceptance Test Driven Development (ATDD) using Cucumber framework with LambdaTest cloud infrastructure for testing the LambdaTest E-Commerce Playground.

Table of Contents

Features

  • Parallel test execution (3 concurrent threads)
  • Professional SLF4J logging with Logback configuration
  • Enhanced LambdaTest integration with automatic status reporting
  • Unique test naming for easy dashboard identification
  • Robust error handling for real-world scenarios (out-of-stock products)
  • Page Object Model with reusable components

Prerequisites

Setup

  1. Navigate to ATDD module:

    cd atdd-guide
  2. Set LambdaTest credentials (choose one method):

    Option A: Environment Variables

    export LT_USERNAME=your_username
    export LT_ACCESS_KEY=your_access_key

    Option B: Maven System Properties (Recommended)

    # Pass credentials directly with Maven command
    mvn verify -DLT_USERNAME=your_username -DLT_ACCESS_KEY=your_access_key
  3. Install dependencies:

    mvn clean install

Project Structure

atdd-guide/
├── src/main/java/com/lambdatest/atdd/
│   ├── config/         # Configuration classes
│   ├── core/           # WebDriver factory & utilities
│   └── pages/          # Page Object Model classes
├── src/test/java/com/lambdatest/atdd/
│   ├── context/        # Test context management
│   ├── hooks/          # Cucumber hooks
│   ├── runners/        # Test runners
│   └── steps/          # Step definitions
└── src/test/resources/features/ecommerce/
    ├── product-search.feature
    └── shopping-cart.feature

Running Tests

Parallel Execution (Recommended)

# Run all tests (parallel) with credentials
mvn clean verify -DLT_USERNAME=your_username -DLT_ACCESS_KEY=your_access_key

# Run specific test suites
mvn verify -DLT_USERNAME=your_username -DLT_ACCESS_KEY=your_access_key -Dcucumber.filter.tags="@smoke"
mvn verify -DLT_USERNAME=your_username -DLT_ACCESS_KEY=your_access_key -Dcucumber.filter.tags="@critical"
mvn verify -DLT_USERNAME=your_username -DLT_ACCESS_KEY=your_access_key -Dcucumber.filter.tags="@regression"

Sequential Execution (For Debugging)

# Using shell script
./run-atdd-tests.sh smoke

# Direct Cucumber CLI
java -cp "target/test-classes:target/classes:$(mvn dependency:build-classpath -q -Dmdep.outputFile=/dev/stdout)" io.cucumber.core.cli.Main --glue com.lambdatest.atdd --plugin pretty src/test/resources/features/ecommerce --tags "@ecommerce"

Test Scenarios

Product Search (@ecommerce @smoke)

  • Successful product search (iMac, HTC, Canon, Samsung, HP)
  • Empty search handling
  • No results scenarios

Shopping Cart (@ecommerce @critical)

  • Add product to cart with out-of-stock handling
  • Cart functionality verification
  • JavaScript click fallback for complex interactions

Test Results

8 Scenarios (8 passed)
31 Steps (31 passed)
1m49s (parallel execution)

2025-08-25 05:11:29.253 [ForkJoinPool-1-worker-1] INFO  c.l.atdd.core.WebDriverFactory - LambdaTest: Test marked as PASSED
2025-08-25 05:11:29.253 [ForkJoinPool-1-worker-1] INFO  c.l.atdd.core.WebDriverFactory - LambdaTest Session: 41dbe58994649d3a0edf4411e52c088f
2025-08-25 05:11:29.253 [ForkJoinPool-1-worker-1] INFO  c.l.atdd.core.WebDriverFactory - Dashboard: https://automation.lambdatest.com/build

Configuration

Parallel Execution (cucumber.properties)

cucumber.execution.parallel.enabled=true
cucumber.execution.parallel.config.fixed.parallelism=3

Maven Configuration (pom.xml)

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <parallel>methods</parallel>
        <threadCount>3</threadCount>
    </configuration>
</plugin>

Professional Logging (logback-test.xml)

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

LambdaTest Status Reporting

Tests automatically report PASSED/FAILED status to LambdaTest dashboard with session tracking and direct links.


This ATDD implementation demonstrates production-ready acceptance testing with parallel execution and comprehensive cloud integration.

About

A comprehensive guide to Java unit testing and ATDD with Selenium WebDriver and LambdaTest. Features cross-browser testing, parallel execution, Cucumber BDD, and professional logging for both unit tests and acceptance test automation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published