cucumber
FreeNo executable scriptsNot checkedCucumber runs behavior-driven (BDD) tests written as plain-language Gherkin feature files and matches each Given/When/Then step to code. Use when the user…
by TerminalSkills★ 221 GitHub starsAbout this skill
Cucumber
Overview
Cucumber executes specifications written in Gherkin: each Given/When/Then line in a .feature file is matched to a step definition function, so scenarios double as living documentation that developers, testers and stakeholders can all read. This skill covers cucumber-js (@cucumber/cucumber, version 13): feature files, step definitions in TypeScript, the World and hooks, profiles, filtering by tag, and CI.
Instructions
Initial Assessment
- Language — JavaScript or TypeScript (this skill covers cucumber-js; other languages have their own Cucumber implementations)
- Scope — API testing, UI testing, or both?
- Team — Who writes feature files? (developers, QA, product)
- Existing tests — Adding BDD to an existing suite or starting fresh?
Setup (JavaScript)
# Install Cucumber.js with TypeScript support. Install it per project, never globally.
npm install --save-dev @cucumber/cucumber tsx typescript @types/node
mkdir -p features/step_definitions features/support
Feature File
# features/login.feature
@login
Feature: User login
As a registered user
I want to log in to my account
So that I can reach my dashboard
Background:
Given a registered user "[email protected]" with password "Tr4il-Mix-88"
@smoke
Scenario: Successful login with valid credentials
When I log in as "[email protected]" with password "Tr4il-Mix-88"
Then I should be redirected to "/dashboard"
And I should see the message "Welcome back"
Scenario: Failed login with a wrong password
When I log in as "[email protected]" with password "tr4il-mix"
Then I should see the error "Invalid credentials"
Scenario Outline: Login validation
When I log in as "<email>" with password "<password>"
Then I should see the error "<error>"
Examples:
| email | password | error |
| | Tr4il-Mix-88 | Email is required |
| [email protected] | | Password is required |
| not-an-email | Tr4il-Mix-88 | Invalid email format |
Step Definitions
// features/step_definitions/login.steps.ts — maps Gherkin steps to code.
// Use `function`, not arrow functions: Cucumber binds the World to `this`.
import assert from 'node:assert/strict';
import { Given, When, Then } from '@cucumber/cucumber';
import type { AppWorld } from '../support/world';
Given('a registered user {string} with password {string}',
function (this: AppWorld, email: string, password: string) {
this.auth.register(email, password);
});
When('I log in as {string} with password {string}',
function (this: AppWorld, email: string, password: string) {
this.result = this.auth.login(email, password);
});
Then('I should be redirected to {string}', function (this: AppWorld, path: string) {
assert.equal(this.result?.redirect, path);
});
Then('I should see the message {string}', function (this: AppWorld, message: string) {
assert.equal(this.result?.message, message);
});
Then('I should see the error {string}', function (this: AppWorld, error: string) {
assert.equal(this.result?.ok, false);
assert.equal(this.result?.error, error);
});
Hooks and World
// features/support/world.ts — a fresh World instance is created for every scenario.
import { setWorldConstructor, World } from '@cucumber/cucumber';
import { AuthService, type LoginResult } from '../../src/auth';
export interface Params { appUrl: string }
export class AppWorld extends World<Params> {
auth = new AuthService();
result?: LoginResult;
}
setWorldConstructor(AppWorld);
// features/support/hooks.ts — setup and teardown around scenarios.
import { After, Before, BeforeAll, Status, setDefaultTimeout } from '@cucumber/cucumber';
import type { AppWorld } from './world';
setDefaultTimeout(10_000); // steps and hooks time out after 5000 ms by default
BeforeAll(async function () {
// one-time setup; no World here, but this.parameters is available
});
Before({ tags: '@smoke' }, async function (this: AppWorld) {
this.log(`running against ${this.parameters.appUrl}`);
});
After(async function (this: AppWorld, { result, pickle }) {
if (result?.status === Status.FAILED) {
this.attach(JSON.stringify(this.result, null, 2), 'application/json');
this.log(`failed: ${pickle.name}`);
}
});
Cucumber Configuration
// cucumber.js — profiles for a CommonJS project (no "type": "module" in package.json).
const common = {
requireModule: ['tsx/cjs'],
require: ['features/support/**/*.ts', 'features/step_definitions/**/*.ts'],
worldParameters: { appUrl: process.env.APP_URL || 'http://localhost:3000' },
};
module.exports = {
default: {
...common,
format: ['progress', ['html', 'reports/cucumber.html']],
},
ci: {
...common,
format: ['summary', ['junit', 'rep
Install cucumber in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the cucumber skill do?
Cucumber runs behavior-driven (BDD) tests written as plain-language Gherkin feature files and matches each Given/When/Then step to code. Use when the user wants to write feature files, implement step definitions in JavaScript or TypeScript with cucumber-js, share state through a World, add hooks, tags and profiles, or run BDD scenarios in CI. Also use when the user mentions "cucumber," "BDD," "Gherkin," "feature files," "given-when-then," "step definitions," or "behavior-driven." For contract testing, see pact.
How do I install the cucumber skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the cucumber skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
by Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
by Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
by Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
by Anthropic