Skip to main content

dochia replay

The replay command allows you to re-execute previously run Dochia tests. This is useful for debugging, regression testing, and validating fixes after issues have been identified.

Basic Usage

dochia replay <tests>[,<tests>...] [OPTIONS]

Required Parameters

  • <tests> - Test identifiers to replay (comma-separated list)

Quick Examples

# Replay a single test from default report folder
dochia replay Test1

# Replay multiple tests
dochia replay Test1,Test5,Test12

# Replay with custom JSON file
dochia replay /path/to/Test1.json

# Replay against different server
dochia replay Test1 -s http://staging.api.com

Test Identification

Default Report Folder

When you provide test names without file extensions, Dochia looks for them in the default dochia-report folder:

# These look in ./dochia-report/ folder
dochia replay Test1
dochia replay Test1,Test5,Test12

Custom JSON Files

When you provide paths with .json extension, Dochia treats them as file paths:

# Replay from specific JSON file
dochia replay /path/to/Test1.json

# Replay from multiple JSON files
dochia replay results1.json,results2.json,/full/path/results3.json

Finding Test Names

To find available test names, check your report folder:

# List available tests in default report folder
ls dochia-report/

# Look for Test*.json files
ls dochia-report/Test*.json

Server Override

Change Target Server

Replay tests against a different server than the original:

# Original tests ran against localhost, replay against staging
dochia replay Test1,Test2 -s https://staging-api.example.com

# Replay against production for validation
dochia replay Test1 -s https://api.production.com

This is particularly useful for:

  • Environment Testing - Run the same tests across dev/staging/prod
  • Load Balancer Testing - Test different server instances
  • Migration Validation - Verify behavior after server changes

Header Override

Authentication Updates

Override headers from the original test, commonly used for authentication:

# Update authentication token
dochia replay Test1 -H "Authorization=Bearer new-token-123"

# Update multiple headers
dochia replay Test1 \
-H "Authorization=Bearer new-token" \
-H "X-API-Version=v2" \
-H "X-Client-ID=new-client"

Header Precedence

Headers specified with -H take precedence over headers stored in the replay files:

# This will override any existing Authorization header
dochia replay Test1 -H "Authorization=Bearer updated-token"

Authentication Options

Basic Authentication

# Username/password authentication
dochia replay Test1 -u "username:password"

Dynamic Authentication

# Refresh authentication periodically
dochia replay Test1,Test2,Test3 \
--auth-refresh 1800 \
--auth-refresh-script ./get-fresh-token.sh

SSL/TLS Configuration

# Client certificate authentication
dochia replay Test1 \
--ssl-keystore client-cert.p12 \
--ssl-keystore-password "$KEYSTORE_PASS" \
--ssl-key-password "$KEY_PASS"

Proxy Settings

# Full proxy URL
dochia replay Test1 --proxy http://proxy.company.com:8080

# Separate host and port
dochia replay Test1 --proxy-host proxy.company.com --proxy-port 8080

Output Options

Save Updated Results

Save the replay results to a new location:

# Save to custom output folder
dochia replay Test1 --output ./replay-results

# Save with timestamp for comparison
dochia replay Test1 --output ./replay-$(date +%Y%m%d-%H%M%S)

The output folder will contain TestXXX.json files with updated responses from the replay.

Verbose Output

# Detailed execution information
dochia replay Test1 -v

Practical Use Cases

Debugging Failed Tests

# Replay a failed test with verbose output to debug
dochia replay Test5 -v

# Replay with updated authentication
dochia replay Test5 -H "Authorization=Bearer fresh-token" -v

Environment Validation

# Test the same scenarios across environments
dochia replay Test1,Test2,Test3 -s https://dev-api.example.com --output ./dev-results
dochia replay Test1,Test2,Test3 -s https://staging-api.example.com --output ./staging-results
dochia replay Test1,Test2,Test3 -s https://prod-api.example.com --output ./prod-results

Regression Testing

# After fixing bugs, replay the failing tests
dochia replay Test8,Test15,Test23 \
-s http://localhost:8080 \
--output ./post-fix-results \
-v

Load Balancer Testing

# Test against different server instances
dochia replay Test1 -s https://api-server-1.example.com --output ./server1-results
dochia replay Test1 -s https://api-server-2.example.com --output ./server2-results
dochia replay Test1 -s https://api-server-3.example.com --output ./server3-results

Authentication Token Refresh

# Replay tests with fresh authentication
dochia replay Test1,Test2,Test3 \
--auth-refresh-script ./refresh-oauth-token.sh \
--output ./fresh-auth-results

Advanced Examples

Complete Environment Migration Test

# Replay critical tests against new environment
dochia replay Test1,Test5,Test12,Test18 \
-s https://new-api-environment.com \
-H "Authorization=Bearer $NEW_ENV_TOKEN" \
-H "X-Environment=production" \
--output ./migration-validation \
--ssl-keystore ./new-env-cert.p12 \
--ssl-keystore-password "$NEW_CERT_PASS" \
-v

Automated Regression Testing

#!/bin/bash
# Script for automated regression testing

# Get failed test IDs from previous run
FAILED_TESTS=$(grep -l '"result":"ERROR"' dochia-report/Test*.json | \
sed 's/.*Test\([0-9]*\)\.json/Test\1/' | \
tr '\n' ',' | sed 's/,$//')

if [ -n "$FAILED_TESTS" ]; then
echo "Replaying failed tests: $FAILED_TESTS"
dochia replay $FAILED_TESTS \
-s http://localhost:8080 \
--output ./regression-test-$(date +%Y%m%d-%H%M%S) \
-v
else
echo "No failed tests to replay"
fi

Multi-Environment Comparison

# Compare API behavior across environments
for env in dev staging prod; do
echo "Testing $env environment..."
dochia replay Test1,Test2,Test3 \
-s https://$env-api.example.com \
-H "Authorization=Bearer ${env^^}_TOKEN" \
--output ./comparison-$env \
-v
done

Result Analysis

Comparing Results

After replaying tests, you can compare results:

# Compare original vs replay results
diff dochia-report/Test1.json replay-results/Test1.json

# Compare across environments
diff dev-results/Test1.json staging-results/Test1.json

Automated Validation

# Check if replay results match expectations
jq '.response.statusCode' replay-results/Test*.json | sort | uniq -c

Best Practices

Test Selection

  1. Start Small - Replay individual tests first to verify setup
  2. Failed Tests First - Focus on previously failed tests for debugging
  3. Critical Path - Prioritize business-critical functionality tests
  4. Environment Specific - Select tests relevant to target environment

Authentication Management

  1. Fresh Tokens - Always use current authentication tokens
  2. Environment Tokens - Use appropriate tokens for each environment
  3. Token Refresh - Use --auth-refresh-script for long-running replays
  4. Security - Never hardcode credentials in scripts

Output Organization

  1. Timestamped Folders - Use timestamps in output folder names
  2. Environment Labels - Include environment names in output paths
  3. Comparison Structure - Organize results for easy comparison
  4. Cleanup - Regularly clean up old replay results

Exit Codes

CodeMeaning
0Successful execution
191Usage error (incorrect arguments)
192Internal execution error

See Also