Skip to content

E2E automation framework using Selenium WebDriver, Jest, and Cucumber with Page Object Model. Developed with Generative AI.

Notifications You must be signed in to change notification settings

Louissilver/selenium_jest

Repository files navigation

Selenium + Jest + Cucumber Automation Framework

CI PR Validation Release Node.js Version License: MIT Selenium Jest Cucumber

A comprehensive E2E automation framework built with Selenium WebDriver, Jest, and Cucumber.js following the Page Object Model (POM) pattern.

πŸ“‹ Table of Contents

πŸš€ Features

  • Selenium WebDriver for browser automation
  • Cucumber.js for BDD-style feature files
  • Jest for unit testing helpers and factories
  • Page Object Model with separated Elements layer
  • HTML Reports for both E2E and unit tests
  • ESLint with Airbnb configuration
  • Husky for Git hooks (pre-commit linting, commit message validation)
  • Environment-based configuration
  • Screenshot capture on test failures

πŸ“ Project Structure

β”œβ”€β”€ .husky/                     # Git hooks
β”œβ”€β”€ .vscode/                    # VS Code settings
β”œβ”€β”€ reports/                    # Test reports and screenshots
β”‚   β”œβ”€β”€ cucumber/              # Cucumber HTML reports
β”‚   β”œβ”€β”€ jest/                  # Jest HTML reports
β”‚   └── screenshots/           # Failure screenshots
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/                # Configuration files
β”‚   β”‚   β”œβ”€β”€ env.js            # Environment configuration
β”‚   β”‚   β”œβ”€β”€ selenium.js       # WebDriver setup
β”‚   β”‚   β”œβ”€β”€ cucumber.js       # Cucumber hooks
β”‚   β”‚   └── jest.setup.js     # Jest setup
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   └── factories/        # Test data factories
β”‚   β”‚       └── userFactory.js
β”‚   β”œβ”€β”€ elements/             # Element selectors
β”‚   β”‚   └── home.elements.js
β”‚   β”œβ”€β”€ helpers/              # Utility functions
β”‚   β”‚   β”œβ”€β”€ wait.js          # Wait helpers
β”‚   β”‚   └── assert.js        # Assertion helpers
β”‚   β”œβ”€β”€ pages/               # Page Object classes
β”‚   β”‚   β”œβ”€β”€ base.page.js     # Base page class
β”‚   β”‚   └── home.page.js     # Home page class
β”‚   └── tests/
β”‚       β”œβ”€β”€ features/        # Cucumber feature files
β”‚       β”‚   └── home.feature
β”‚       └── step-definitions/ # Step definition files
β”‚           └── home.steps.js
β”œβ”€β”€ __tests__/               # Jest unit tests
β”‚   └── userFactory.test.js
β”œβ”€β”€ tools/                   # Utility scripts
β”‚   └── cucumber-html-report.js
└── Configuration files...

πŸ› οΈ Setup

Prerequisites

  • Node.js (>= 18)
  • Chrome/Firefox/Edge browser
  • ChromeDriver/GeckoDriver/EdgeDriver (for local execution)

Installation

  1. Clone the repository

  2. Install dependencies:

    npm install
  3. Copy environment file:

    cp .env.example .env
  4. Initialize Husky:

    npm run prepare

βš™οΈ Configuration

Edit .env file to configure:

BASE_URL=https://gadget-shop-complete-xf3n.bolt.host
BROWSER=chrome          # chrome, firefox, edge
HEADLESS=true          # true/false
DEFAULT_TIMEOUT=30000  # milliseconds

πŸ§ͺ Running Tests

E2E Tests (Cucumber)

# Run all E2E tests
npm run test:e2e

# Generate Cucumber HTML report
npm run report:cucumber

Unit Tests (Jest)

# Run unit tests
npm run test:unit

# Run all tests
npm run test:all

Linting

# Check code style
npm run lint

# Fix linting issues
npm run lint:fix

πŸ“Š Reports

  • Cucumber Reports: reports/cucumber/index.html
  • Jest Reports: reports/jest/report.html
  • Screenshots: reports/screenshots/ (on test failures)

πŸ—οΈ Architecture

Page Object Model

  • Elements Layer: Centralized selectors (src/elements/)
  • Page Layer: Page interactions (src/pages/)
  • Step Definitions: Test orchestration (src/tests/step-definitions/)

Configuration

  • Environment: src/config/env.js
  • WebDriver: src/config/selenium.js
  • Hooks: src/config/cucumber.js

Helpers & Utilities

  • Wait Helpers: Custom wait conditions
  • Assert Helpers: Enhanced assertions
  • Data Factories: Test data generation with Faker.js

πŸ”§ Development

Adding New Tests

  1. Create Feature File: Add .feature file in src/tests/features/
  2. Add Elements: Define selectors in src/elements/
  3. Create Page Object: Implement page class in src/pages/
  4. Write Step Definitions: Add steps in src/tests/step-definitions/

Code Quality

  • ESLint with Airbnb configuration
  • Pre-commit hooks for linting
  • Conventional commit messages
  • Automatic screenshot capture on failures

🚦 CI/CD Pipeline (GitHub Actions)

The framework includes comprehensive GitHub Actions workflows for automated testing and deployment:

πŸ”„ Continuous Integration (ci.yml)

Triggered on push to main and develop branches:

  • Linting & Quality: ESLint validation with Airbnb configuration
  • Commit Validation: Commitlint checks for conventional commit messages
  • Unit Tests: Jest tests with coverage reporting and HTML output
  • E2E Tests: Cucumber + Selenium tests in headless Chrome
  • Artifacts: Automatic upload of test reports and failure screenshots
  • Environment: Node.js 20.x with Chrome/ChromeDriver setup

πŸ” Pull Request Validation (pr-validation.yml)

Triggered on pull requests to main and develop:

  • Code Quality: ESLint checks with inline PR comments
  • Commit Messages: Commitlint validation for PR commits
  • Unit Testing: Fast Jest execution for quick feedback
  • PR Comments: Automated status updates on PR with test results

πŸš€ Release Pipeline (release.yml)

Triggered on Git tags (e.g., v1.0.0):

  • Full Test Suite: Complete E2E and unit test execution
  • Release Notes: Automatic generation from commit history
  • GitHub Release: Creates release with artifacts and reports
  • Artifact Retention: 90-day retention for release reports

πŸ“Š CI/CD Features

  • Parallel Execution: Unit and E2E tests run in parallel for faster feedback
  • Headless Testing: Chrome headless mode for reliable CI execution
  • Artifact Management: Test reports, screenshots, and logs preserved
  • Multi-Environment: Support for different test environments via secrets
  • Failure Handling: Screenshot capture and detailed error reporting
  • Cache Optimization: Node modules and browser binaries cached

πŸƒβ€β™‚οΈ Running Tests by Tags

# Smoke tests (quick validation)
npm run test:e2e:smoke

# Regression tests (comprehensive)
npm run test:e2e:regression

# Critical path tests
npm run test:e2e -- --tags "@critical"

πŸ”§ CI Configuration

The workflows are configured for:

  • Node.js: LTS 20.x for stability
  • Browsers: Chrome with ChromeDriver auto-installation
  • Timeouts: 60-second step timeout, 30-second Jest timeout
  • Reporting: JSON and HTML formats with artifact upload
  • Security: Environment variables and secrets management

πŸ“ Example Test

Feature: Home Page
  Scenario: Home page loads successfully
    Given I am on the home page
    When the page finishes loading
    Then I should see the main content
    And I should see the header

🀝 Contributing

  1. Follow conventional commit messages
  2. Run linting before commits
  3. Add tests for new features
  4. Update documentation as needed

πŸ“„ License

MIT License

About

E2E automation framework using Selenium WebDriver, Jest, and Cucumber with Page Object Model. Developed with Generative AI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published