Skip to content

rohitsaraswat7865/Performance_Testing_Cucumber_K6_Browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

K6 Browser Performance Testing Framework

🚀 Comprehensive UI performance testing framework combining k6 browser automation with Cucumber BDD scenarios

✨ Features

  • 🎯 Dual Testing Modes: Main page load time & component-specific performance measurement
  • 🌐 Network Simulation: WiFi, 4G, 3G network throttling support
  • 💻 CPU Throttling: High/Low CPU performance simulation
  • 📸 Auto Screenshots: Pass/fail screenshot capture with timestamped filenames
  • 📊 Web Vitals: Comprehensive metrics (FCP, LCP, CLS, TTFB)
  • 🔍 Component Validation: Visibility, accessibility, and text content verification
  • 📝 BDD Scenarios: Human-readable test scenarios using Gherkin syntax
  • ⚡ Robust Parsing: Automatic unit conversion (ms ↔ s) and metric extraction

🛠️ Technology Stack

  • k6 with browser module for performance testing
  • Cucumber.js for BDD-style test scenarios
  • Chrome/Chromium browser automation
  • Node.js runtime environment

📋 Requirements

  • Node.js: v18+ (tested with v24.4.1)
  • k6: With browser module support
  • Chrome/Chromium: Installed and accessible in system PATH
  • OS: Windows, macOS, or Linux

🚀 Quick Start

1. Installation

# Clone the repository
git clone <repo-url>
cd performance-testing-cucumber-k6-browser

# Install dependencies
npm install

# Verify k6 installation
npm run verify-k6

2. Run Tests

# Run all performance tests with automatic logging
npm test

# The framework will automatically:
# ✅ Validate environment variables
# ✅ Execute BDD scenarios with network/CPU simulation
# ✅ Generate performance metrics and screenshots
# ✅ Validate against defined thresholds
# ✅ Save complete test output to logs/test-output.log

📄 Logging & Output

Automatic Log Generation

  • 📝 All test output automatically saved to logs/test-output.log
  • 🔍 Complete execution details including K6 metrics, timings, and results
  • 📊 Performance data with Web Vitals and component validation
  • 🖼️ Screenshot references with full file paths
  • ⚠️ Error capture both stdout and stderr logged

Log File Contents

├── Node.js version and Cucumber info
├── Network/CPU simulation details
├── K6 browser automation logs
├── Performance timing measurements
├── Web Vitals metrics (FCP, LCP, CLS, TTFB)
├── Component validation results
├── Screenshot generation confirmations
└── Final test summary (scenarios/steps passed)

📁 Project Structure

├── features/                          # BDD test scenarios
│   └── google_search_performance.feature    # Google search performance tests
├── step_definitions/                  # Cucumber implementation
│   ├── hook.js                       # Setup, teardown, environment config
│   ├── logConfig.js                  # Logging configuration
│   └── steps.js                      # Step definitions & metric parsing
├── k6/                               # K6 performance scripts
│   └── ui_performance.js             # Browser automation & measurement
├── screenshots/                      # Auto-generated screenshots
│   └── [timestamp]_[scenario]_[status].png
├── logs/                            # Test execution logs
├── cucumber.js                      # Cucumber configuration
├── k6env.yaml                       # K6 environment settings
├── crypto-util.js                   # Utility functions
├── run-parallel-tests.js            # Parallel execution runner
└── package.json                     # Dependencies & scripts

🎯 Test Scenarios

Main Page Load Time Tests

  • WiFi + HighCPU: < 5 seconds
  • 4G + LowCPU: < 8 seconds
  • 3G: < 12 seconds
  • WiFi + LowCPU: < 6 seconds

Component Performance Tests

  • WiFi + HighCPU: < 6 seconds
  • 4G + HighCPU: < 6 seconds

🏷️ Network & CPU Tags

Network Simulation Tags

  • @WIFI - WiFi Network Profile
  • @4G - Regular 4G Network Profile
  • @3G - Fast 3G Network Profile

CPU Simulation Tags

  • @HighCPU - High CPU Performance (No throttling)
  • @LowCPU - Low CPU Performance (4x throttling)

📊 Metrics Collected

Performance Metrics

  • Main Page Load Time: Network idle-based page load measurement
  • Subcomponent Load Time: Component-specific performance timing
  • DOM Content Loaded: DOM parsing completion time
  • Network Idle Time: Network activity completion

Web Vitals

  • FCP (First Contentful Paint): Time to first content render
  • LCP (Largest Contentful Paint): Time to largest content render
  • CLS (Cumulative Layout Shift): Visual stability measurement
  • TTFB (Time to First Byte): Server response time

Component Validation

  • ✅ Element visibility
  • ✅ Element accessibility/enabled state
  • ✅ Element interactability
  • ✅ Paint work completion
  • ✅ Expected text content presence
  • ✅ Text visibility

🔧 Configuration

Environment Variables

# Set target URL (automatically handled by framework)
TEST_URL="https://www.google.com"

Customizing Thresholds

Edit thresholds in features/google_search_performance.feature:

Then the main page load time should be less than 5 seconds
Then each subcomponent load time should be less than 6 seconds

Adding New Test Scenarios

  1. Create new scenarios in features/*.feature files
  2. Use network/CPU tags for simulation: @WIFI @HighCPU
  3. Define selectors and expected text in data tables
  4. Set appropriate thresholds for your use case

📸 Screenshot Management

Screenshots are automatically captured with descriptive filenames:

screenshots/2025-08-01T15-21-43_Load_Google_homepage_WIFI_HighCPU_page_pass_VU1_Iter0.png

Format: [timestamp]_[scenario]_[tags]_[type]_[status]_[details].png

🐛 Troubleshooting

Common Issues

❌ K6 not found

# Install k6 with browser support
# Visit: https://k6.io/docs/getting-started/installation/

❌ Chrome/Chromium not found

# Ensure Chrome is installed and in PATH
# Or set CHROME_BIN environment variable

❌ Module type warnings

# Add "type": "module" to package.json to eliminate warnings

Debug Mode

View detailed logs in logs/test-output.log or check the console output during test execution.

🤝 Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Add test scenarios for new functionality
  4. Ensure all tests pass: npm test
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. Open Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🏆 Test Results

Latest Test Run: 6/6 scenarios passing ✅

Performance Metrics

  • Main page load times: 2.25-3.74s across all network conditions
  • Subcomponent load times: 0.31-0.49s component validation
  • Total execution time: ~27 seconds for full test suite
  • Framework: 100% functional with proper metric collection

Test Coverage

  • ✅ WiFi + HighCPU: 3.74s (< 5s limit)
  • ✅ 4G + LowCPU: Performance validated
  • ✅ 3G: Performance validated
  • ✅ WiFi + LowCPU: Performance validated
  • ✅ Component tests: Both scenarios passing

Output Generated

  • 📄 Complete logs: Saved to logs/test-output.log (657 lines)
  • 📸 Screenshots: Auto-captured for all scenarios
  • 📊 Web Vitals: FCP, LCP, CLS, TTFB metrics collected
  • 🔍 Component validation: Visibility, accessibility, text content verified

Built with ❤️ using K6 Browser + Cucumber.js

About

Comprehensive UI performance testing framework combining k6 browser automation with Cucumber BDD scenarios

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors