npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

k6-cucumber-steps

v2.0.7

Published

Generate k6 test scripts from Cucumber feature files

Downloads

1,532

Readme

k6-cucumber-steps 🥒🧪

npm version npm downloads license Cucumber Node.js Sponsor Build Status

Run k6 performance/load tests using Cucumber BDD syntax with ease.


✨ Features

  • ✅ Cucumber + Gherkin for writing k6 tests to generate JSON and HTML reports.

  • ✅ Flexible configuration through Cucumber data tables.

  • ✅ Support for JSON body parsing and escaping

  • ✅ Dynamic request body generation using environment variables, Faker templates, and JSON file includes.

  • .env + K6.env-style variable resolution ({{API_KEY}})

  • ✅ Support for headers, query params, stages

  • ✅ Supports multiple authentication types: API key, Bearer token, Basic Auth, and No Auth.

  • ✅ Clean-up of temporary k6 files after execution

  • ✅ Built-in support for distributed load testing with stages

  • ✅ TypeScript-first 🧡

✨ Key Enhancements

  • 🚀 One-Command Setup: Use init to scaffold a full k6 project with sample features and steps.
  • 📂 Centralized Reporting: Automatically generates HTML and JSON reports in a dedicated reports/ folder.
  • 🔑 Dynamic Auth Storage: Store tokens from one scenario and reuse them in another via globalThis memory.
  • 🛠 JS & TS Support: Generate your project in pure JavaScript or TypeScript.
  • 📊 Metric Segmentation: Scenarios are wrapped in k6 group() blocks for cleaner reporting.

✨ New: Hybrid Performance Testing

You can now combine Protocol-level (HTTP) load testing and Browser-level (Web Vitals) testing in a single Gherkin suite.

  • API Testing: High-concurrency stress testing at the protocol layer.
  • Browser Testing: Real browser rendering metrics (LCP, CLS, FID) using k6 browser (Chromium).


🚀 Quick Start (Scaffolding a New Project)

🧪 Usage Examples

Initialize in current directory:

npx k6-cucumber-steps init
# or
npx k6-cucumber-steps init .

→ Creates features/, steps/, generated/, etc. in your current folder

Initialize in a new subdirectory:

# Initialize in current dir with TypeScript (default)
npx k6-cucumber-steps init

# Initialize in current dir with JavaScript
npx k6-cucumber-steps init -l js

# Initialize in subdirectory with JS
npx k6-cucumber-steps init my-project -l js

→ Creates my-project/ with full structure


🛠️ Project Structure

The init command creates a clean, industry-standard directory structure:

.
├── data/                 # User credentials and seed data
├── features/             # Gherkin .feature files
├── steps/                # Step definitions (logic)
├── generated/            # Compiled k6 scripts (auto-generated)
├── reports/              # HTML & JSON test results
└── package.json          # Test scripts and dependencies

🛠️ CLI Reference

Options

The npx k6-cucumber-steps command accepts the following options:

init

Scaffolds a new project.

  • --lang <js|ts>: Choose the project language (default: ts).
  • --force: Overwrite existing files in the current directory.
  • .command("init") description: "Initialize a new k6-cucumber project
  • .argument "[path]": "Output directory path", "./k6-test-project"
  • -f, --feature <path>: "Path to feature files", "./features"
  • -t, --tags <string>: Cucumber tags to filter scenarios (e.g., @smoke and not @regression).

generate

Parses your .feature files and creates the k6-compatible execution scripts in the generated/ folder.

  • .command("generate")
  • .description: ("Generate k6 scripts from feature files")
  • --lang <js|ts>: Choose the project language (default: ts).

run (Direct Execution)

For projects where you prefer to run single features directly.

  • -f, --feature <path>: Path to specific feature.

🧼 Clean-up & Maintenance

  • npm run clean: Wipes the reports/ and generated/ folders.
  • npm run report: Opens the latest HTML report in your default browser.

🔑 Advanced Authentication Flow

We now support Dynamic Handshake Authentication. You can log in once in an initial scenario, store the token, and all subsequent scenarios will automatically be authenticated.

Step 1: Login and Capture

Scenario: Authenticate and Store Token
  When I authenticate with the following url and request body as "standard_user":
    | endpoint | username      | password    |
    | /login   | paschal_qa    | pass123     |
  And I store "data.token" in "data/standard_user.json"

Step 2: Reuse Token

Background:
  And I am authenticated as a "standard_user" # Lookups token from memory

🚀 Usage

Browser Testing (@browser)

Simply tag your scenario with @browser. The generator will automatically launch a Chromium instance, manage the page lifecycle, and inject the page object into your steps.

@browser
Scenario: Verify Homepage UI and Web Vitals
  Given the base URL is "https://test.k6.io"
  When I navigate to the "/" page
  Then I see the text on the page "Collection of simple web-pages"

Dynamic Auth & Storage

Log in via API and reuse the token across any scenario (including Browser scenarios).

Scenario: Login and Save Session
  When I authenticate with the following url and request body as "admin":
    | endpoint | username | password |
    | /login   | admin    | p@ss123  |
  And I store "token" in "data/admin.json"

🧼 Step Definitions Reference

| Step Example | Layer | Description | | ------------------------------------- | ------- | ---------------------------- | | When I make a GET request to "/api" | API | Standard HTTP request. | | When I navigate to the "/home" page | Browser | Opens URL in Chromium. | | And I click the button ".submit" | Browser | Interacts with DOM elements. | | And I store "path" in "file.json" | Both | Dynamic data persistence. |


📊 Automated Reporting

Every test run now produces a rich HTML dashboard. Your scenarios are grouped naturally, making it easy to identify which specific Gherkin scenario is causing performance bottlenecks.

Find your reports at:

  • reports/summary.html: Interactive dashboard.
  • reports/results.json: Full k6 metric data.
  • reports/tokens_debug.json: View captured tokens during the run.

Step Definitions

Authentication Steps

When I authenticate with the following url and request body as "standard_user":
| endpoint | username      | password    |
    | /login   | paschal_qa    | pass123     |
And I am authenticated as a "standard_user" # Lookups token from memory

sample features

@smoke @vus:10 @duration:1m
Feature: Comprehensive API Testing

  Background:
    Given the base URL is "https://jsonplaceholder.typicode.com"
    And I set the default headers:
      | Content-Type     | Accept           |
      | application/json | application/json |

  @group:user-api @threshold:http_req_duration=p(95)<500
  Scenario: Get specific user details
    When I make a GET request to "/users/1"
    Then the response status should be 200
    And the response should contain "name"

  @group:load-test @stages:0s-0,20s-10,30s-10,10s-0
  Scenario Outline: Validate multiple user endpoints
    When I make a GET request to "/users/<userId>"
    Then the response status should be <expectedStatus>

    Examples:
      | userId | expectedStatus |
      | 1      | 200            |
      | 5      | 200            |
      | 999    | 404            |

  @group:post-api
  Scenario: Create a post with bulk data
    Given I have the following post data:
      """
      {
        "title": "Performance Test",
        "body": "Testing DataTables and DocStrings",
        "userId": 1
      }
      """
    When I make a POST request to "/posts"
    Then the response status should be 201

Assertion Steps

Then the response status should be 200
Then the response should contain "name"
Then the response status should be <expectedStatus>

💖 Support

If you find this package useful, consider sponsoring me on GitHub. Your support helps me maintain and improve this project!

📄 License

MIT License - @qaPaschalE

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