Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f7c38df
Initial plan
Copilot Aug 23, 2025
638f93a
Enhance test app index page with comprehensive form navigation
Copilot Aug 23, 2025
62eaf55
Add backward compatibility elements for failing tests
Copilot Aug 23, 2025
49aac40
Restore original index.php structure to fix failing acceptance tests
Copilot Aug 23, 2025
b47a96e
Changes before error encountered
Copilot Aug 23, 2025
5dbd842
Fix PHP test app server configuration for React SPA static file serving
Copilot Aug 24, 2025
7758ea9
Changes before error encountered
Copilot Sep 1, 2025
2748649
[WIP] [FEATURE REQUEST](puppeteer) migrate locators from ElementHandl…
Copilot Aug 23, 2025
2528956
DOC: Autogenerate and update documentation
actions-user Aug 23, 2025
0047a65
Fix test statistics reporting issue in pool mode - consolidate result…
Copilot Aug 23, 2025
0cc4fa1
Fix mocha retries losing CodeceptJS-specific properties (opts, tags, …
Copilot Aug 23, 2025
6f8166b
Test Sharding for CI Matrix Purposes with GitHub Workflows (#5098)
Copilot Aug 23, 2025
0d8a72c
API test server to run unit tests, acceptance tests for codeceptjs wi…
Copilot Aug 23, 2025
a56adb1
Enable HTML reporter by default in new CodeceptJS projects with compr…
Copilot Aug 24, 2025
1269332
fix: use platformName for mobile click detection instead of isW3C (An…
mirao Aug 24, 2025
601d06d
[WIP] Bug: built in HTML reporter missing test stats when running run…
Copilot Aug 26, 2025
e371c09
Fix: JSONResponse helper to preserve original onResponse behavior (Fi…
myrepojuly Aug 26, 2025
df36bcf
feat: Add configurable sensitive data masking with custom patterns (#…
Copilot Aug 26, 2025
87b804a
chore(deps-dev): bump @eslint/js from 9.31.0 to 9.34.0 (#5112)
dependabot[bot] Aug 26, 2025
182f5c7
Add Custom Strategy Locators support to Playwright helper (#5090)
Copilot Aug 27, 2025
4a71c75
DOC: Autogenerate and update documentation
actions-user Aug 27, 2025
680208d
fix(playwright): relaunch browser correctly with `restart: 'session'`…
Samuel-StO Aug 28, 2025
819a491
Initial plan
Copilot Aug 23, 2025
2faf34e
Changes before error encountered
Copilot Sep 1, 2025
4811d56
Changes before error encountered
Copilot Sep 1, 2025
2fd3dae
Add comprehensive missing PHP routes to React SPA migration
Copilot Sep 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/SHARDING_WORKFLOWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Test Sharding Workflows

This document explains the GitHub Actions workflows that demonstrate the new test sharding functionality in CodeceptJS.

## Updated/Created Workflows

### 1. `acceptance-tests.yml` (Updated)

**Purpose**: Demonstrates sharding with acceptance tests across multiple browser configurations.

**Key Features**:

- Runs traditional docker-compose tests (for backward compatibility)
- Adds new sharded acceptance tests using CodeceptJS directly
- Tests across multiple browser configurations (Puppeteer, Playwright)
- Uses 2x2 matrix: 2 configs × 2 shards = 4 parallel jobs

**Example Output**:

```
- Sharded Tests: codecept.Puppeteer.js (Shard 1/2)
- Sharded Tests: codecept.Puppeteer.js (Shard 2/2)
- Sharded Tests: codecept.Playwright.js (Shard 1/2)
- Sharded Tests: codecept.Playwright.js (Shard 2/2)
```

### 2. `sharding-demo.yml` (New)

**Purpose**: Comprehensive demonstration of sharding features with larger test suite.

**Key Features**:

- Uses sandbox tests (2 main test files) for sharding demonstration
- Shows basic sharding with 2-way split (`1/2`, `2/2`)
- Demonstrates combination of `--shuffle` + `--shard` options
- Uses `DONT_FAIL_ON_EMPTY_RUN=true` to handle cases where some shards may be empty

### 3. `test.yml` (Updated)

**Purpose**: Clarifies which tests support sharding.

**Changes**:

- Added comment explaining that runner tests are mocha-based and don't support sharding
- Points to sharding-demo.yml for examples of CodeceptJS-based sharding

## Sharding Commands Used

### Basic Sharding

```bash
npx codeceptjs run --config ./codecept.js --shard 1/2
npx codeceptjs run --config ./codecept.js --shard 2/2
```

### Combined with Other Options

```bash
npx codeceptjs run --config ./codecept.js --shuffle --shard 1/2 --verbose
```

## Test Distribution

The sharding algorithm distributes tests evenly:

- **38 tests across 4 shards**: ~9-10 tests per shard
- **6 acceptance tests across 2 shards**: 3 tests per shard
- **Uneven splits handled gracefully**: Earlier shards get extra tests when needed

## Benefits Demonstrated

1. **Parallel Execution**: Tests run simultaneously across multiple CI workers
2. **No Manual Configuration**: Automatic test distribution without maintaining test lists
3. **Load Balancing**: Even distribution ensures balanced execution times
4. **Flexibility**: Works with any number of shards and test configurations
5. **Integration**: Compatible with existing CodeceptJS features (`--shuffle`, `--verbose`, etc.)

## CI Matrix Integration

The workflows show practical CI matrix usage:

```yaml
strategy:
matrix:
config: ['codecept.Puppeteer.js', 'codecept.Playwright.js']
shard: ['1/2', '2/2']
```

This creates 4 parallel jobs:

- Config A, Shard 1/2
- Config A, Shard 2/2
- Config B, Shard 1/2
- Config B, Shard 2/2

Perfect for scaling test execution across multiple machines and configurations.
2 changes: 1 addition & 1 deletion .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Acceptance Tests using docker compose
name: Acceptance Tests

on:
push:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ jobs:
run: './bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
- name: run chromium with restart==browser tests
run: 'BROWSER_RESTART=browser ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
- name: run chromium with restart==session tests
- name: run chromium with restart==session tests on 2 workers split by pool
run: 'BROWSER_RESTART=session ./bin/codecept.js run-workers 2 -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug --by=pool'
- name: run chromium with restart==session tests and
run: 'BROWSER_RESTART=session ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
- name: run firefox tests
run: 'BROWSER=firefox node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/sharding-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Minimal Sharding Test

on:
push:
branches:
- '3.x'
pull_request:
branches:
- '**'

env:
CI: true
FORCE_COLOR: 1

jobs:
test-sharding:
runs-on: ubuntu-latest
name: 'Shard ${{ matrix.shard }}'

strategy:
fail-fast: false
matrix:
shard: ['1/2', '2/2']

steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install --ignore-scripts

- name: Run tests with sharding
run: npx codeceptjs run --config ./codecept.js --shard ${{ matrix.shard }}
working-directory: test/data/sandbox
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm run test:runner
# Note: Runner tests are mocha-based, so sharding doesn't apply here.
# For CodeceptJS sharding examples, see sharding-demo.yml workflow.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ examples/selenoid-example/output
test/data/app/db
test/data/sandbox/steps.d.ts
test/data/sandbox/configs/custom-reporter-plugin/output/result.json
test/data/sandbox/configs/html-reporter-plugin/output/
output/
test/runner/output/
testpullfilecache*
.DS_Store
package-lock.json
Expand Down
26 changes: 14 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ RUN apt-get update && \
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update && apt-get install -y gnupg wget && \
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
apt-get update && \
apt-get install -y google-chrome-stable --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
# Skip Chrome installation for now as Playwright image already has browsers
RUN echo "Skipping Chrome installation - using Playwright browsers"


# Add pptr user.
Expand All @@ -31,17 +27,23 @@ RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
COPY . /codecept

RUN chown -R pptruser:pptruser /codecept
RUN runuser -l pptruser -c 'npm i --loglevel=warn --prefix /codecept'
# Set environment variables to skip browser downloads during npm install
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_SKIP_DOWNLOAD=true
# Install as root to ensure proper bin links are created
RUN cd /codecept && npm install --loglevel=warn
# Fix ownership after install
RUN chown -R pptruser:pptruser /codecept

RUN ln -s /codecept/bin/codecept.js /usr/local/bin/codeceptjs
RUN mkdir /tests
WORKDIR /tests
# Install puppeteer so it's available in the container.
RUN npm i puppeteer@$(npm view puppeteer version) && npx puppeteer browsers install chrome
RUN google-chrome --version
# Skip the redundant Puppeteer installation step since we're using Playwright browsers
# RUN npm i puppeteer@$(npm view puppeteer version) && npx puppeteer browsers install chrome
# RUN chromium-browser --version

# Install playwright browsers
RUN npx playwright install
# Skip the playwright browser installation step since base image already has browsers
# RUN npx playwright install

# Allow to pass argument to codecept run via env variable
ENV CODECEPT_ARGS=""
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ You don't need to worry about asynchronous nature of NodeJS or about various API
- Also plays nice with TypeScript.
- </> Smart locators: use names, labels, matching text, CSS or XPath to locate elements.
- 🌐 Interactive debugging shell: pause test at any point and try different commands in a browser.
- ⚡ **Parallel testing** with dynamic test pooling for optimal load balancing and performance.
- 📊 **Built-in HTML Reporter** with interactive dashboard, step-by-step execution details, and comprehensive test analytics.
- Easily create tests, pageobjects, stepobjects with CLI generators.

## Installation
Expand Down Expand Up @@ -233,6 +235,49 @@ Scenario('test title', () => {
})
```

## HTML Reporter

CodeceptJS includes a powerful built-in HTML Reporter that generates comprehensive, interactive test reports with detailed information about your test runs. The HTML reporter is **enabled by default** for all new projects and provides:

### Features

- **Interactive Dashboard**: Visual statistics, pie charts, and expandable test details
- **Step-by-Step Execution**: Shows individual test steps with timing and status indicators
- **BDD/Gherkin Support**: Full support for feature files with proper scenario formatting
- **System Information**: Comprehensive environment details including browser versions
- **Advanced Filtering**: Real-time filtering by status, tags, features, and test types
- **History Tracking**: Multi-run history with trend visualization
- **Error Details**: Clean formatting of error messages and stack traces
- **Artifacts Support**: Display screenshots and other test artifacts

### Visual Examples

#### Interactive Test Dashboard

The main dashboard provides a complete overview with interactive statistics and pie charts:

![HTML Reporter Dashboard](docs/shared/html-reporter-main-dashboard.png)

#### Detailed Test Results

Each test shows comprehensive execution details with expandable step information:

![HTML Reporter Test Details](docs/shared/html-reporter-test-details.png)

#### Advanced Filtering Capabilities

Real-time filtering allows quick navigation through test results:

![HTML Reporter Filtering](docs/shared/html-reporter-filtering.png)

#### BDD/Gherkin Support

Full support for Gherkin scenarios with proper feature formatting:

![HTML Reporter BDD Details](docs/shared/html-reporter-bdd-details.png)

The HTML reporter generates self-contained reports that can be easily shared with your team. Learn more about configuration and features in the [HTML Reporter documentation](https://codecept.io/plugins/#htmlreporter).

## PageObjects

CodeceptJS provides the most simple way to create and use page objects in your test.
Expand Down
2 changes: 2 additions & 0 deletions bin/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ program
.option('--no-timeouts', 'disable all timeouts')
.option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
.option('--shuffle', 'Shuffle the order in which test files run')
.option('--shard <index/total>', 'run only a fraction of tests (e.g., --shard 1/4)')

// mocha options
.option('--colors', 'force enabling of colors')
Expand Down Expand Up @@ -196,6 +197,7 @@ program
.option('-i, --invert', 'inverts --grep matches')
.option('-o, --override [value]', 'override current config options')
.option('--suites', 'parallel execution of suites not single tests')
.option('--by <strategy>', 'test distribution strategy: "test" (pre-assign individual tests), "suite" (pre-assign test suites), or "pool" (dynamic distribution for optimal load balancing, recommended)')
.option(commandFlags.debug.flag, commandFlags.debug.description)
.option(commandFlags.verbose.flag, commandFlags.verbose.description)
.option('--features', 'run only *.feature files and skip tests')
Expand Down
53 changes: 53 additions & 0 deletions bin/test-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node

/**
* Standalone test server script to replace json-server
*/

const path = require('path')
const TestServer = require('../lib/test-server')

// Parse command line arguments
const args = process.argv.slice(2)
let dbFile = path.join(__dirname, '../test/data/rest/db.json')
let port = 8010
let host = '0.0.0.0'

// Simple argument parsing
for (let i = 0; i < args.length; i++) {
const arg = args[i]

if (arg === '-p' || arg === '--port') {
port = parseInt(args[++i])
} else if (arg === '--host') {
host = args[++i]
} else if (!arg.startsWith('-')) {
dbFile = path.resolve(arg)
}
}

// Create and start server
const server = new TestServer({ port, host, dbFile })

console.log(`Starting test server with db file: ${dbFile}`)

server
.start()
.then(() => {
console.log(`Test server is ready and listening on http://${host}:${port}`)
})
.catch(err => {
console.error('Failed to start test server:', err)
process.exit(1)
})

// Graceful shutdown
process.on('SIGINT', () => {
console.log('\nShutting down test server...')
server.stop().then(() => process.exit(0))
})

process.on('SIGTERM', () => {
console.log('\nShutting down test server...')
server.stop().then(() => process.exit(0))
})
24 changes: 22 additions & 2 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,32 @@ DEBUG=codeceptjs:* npx codeceptjs run

## Run Workers

Run tests in parallel threads.
Run tests in parallel threads. CodeceptJS supports different distribution strategies for optimal performance.

```
```bash
# Run with 3 workers using default strategy (pre-assign tests)
npx codeceptjs run-workers 3

# Run with pool mode for dynamic test distribution (recommended)
npx codeceptjs run-workers 3 --by pool

# Run with suite distribution
npx codeceptjs run-workers 3 --by suite

# Pool mode with filtering
npx codeceptjs run-workers 4 --by pool --grep "@smoke"
```

**Test Distribution Strategies:**

- `--by test` (default): Pre-assigns individual tests to workers
- `--by suite`: Pre-assigns entire test suites to workers
- `--by pool`: Dynamic distribution for optimal load balancing (recommended for best performance)

The pool mode provides the best load balancing by maintaining tests in a shared pool and distributing them dynamically as workers become available. This prevents workers from sitting idle and ensures optimal CPU utilization, especially when tests have varying execution times.

See [Parallel Execution](/parallel) documentation for more details.

## Run Rerun <Badge text="Since 3.3.6" type="warning"/>

Run tests multiple times to detect and fix flaky tests.
Expand Down
Loading
Loading