Use Cucumber.js to run Gherkin scenarios and match their steps to JavaScript or TypeScript functions; use Playwright inside those functions to control the browser. Cucumber does not automate browsers itself, and this setup is support code that connects two separate tools—not a Playwright Test setting.
How Cucumber and Playwright fit together
The execution path is: .feature scenario → Cucumber step definition → Playwright browser, context, and page actions → an assertion. Keep the feature file focused on behavior a reader can understand. Put browser operations in step definitions and, as the project grows, small helper functions or page objects.
Cucumber’s own browser automation guide says it is not a browser automation tool, but works with browser automation tools such as Playwright. Cucumber.js runs scenarios and matches steps; Playwright performs the browser work. Cucumber browser automation · Cucumber.js step definitions
Set up a JavaScript project
The following is a minimal implementation pattern, not an official combined starter template. It uses Node.js, Cucumber.js, and Playwright’s library package. Check the current installation guidance for runtime and package requirements rather than pinning versions from an old example.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
-
Create a project if you do not already have one:
npm init -y. -
Install the test runner and browser automation library:
npm install --save-dev @cucumber/cucumber playwright. -
Install a browser binary supported by Playwright:
npx playwright install chromium. Install other browsers if your tests need them. See Playwright installation and Playwright browsers. -
Create the feature and support-code files shown below. Run Cucumber with explicit paths:
npx cucumber-js features --require features/support/**/*.js.Recommended: Fix Windows Errors and Clear Junk Files in Minutes - Free Scan →Recommended: Crashes or Glitches? A Free Driver Scan Usually Finds the Culprit →Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Playwright’s supported languages include JavaScript and TypeScript. The example here is JavaScript; TypeScript projects need an appropriate way to load TypeScript support code, configured for the project’s Node.js and Cucumber.js versions. Playwright supported languages
Write a feature and connect its steps
Example directory layout:
features/home.feature— readable Gherkin scenario.features/support/world.js— scenario-specific state.features/support/hooks.js— browser setup and cleanup.features/step_definitions/home.js— matching step functions.
features/home.feature:
Feature: Home page
Scenario: Open the home page
Given I open the home page
Then the page title should contain "Example Domain"
features/support/world.js:
const { setWorldConstructor } = require('@cucumber/cucumber');
class CustomWorld {
constructor() {
this.browser = undefined;
this.context = undefined;
this.page = undefined;
}
}
setWorldConstructor(CustomWorld);
features/support/hooks.js:
const { Before, After } = require('@cucumber/cucumber');
const { chromium } = require('playwright');
Before(async function () {
this.browser = await chromium.launch({ headless: true });
this.context = await this.browser.newContext();
this.page = await this.context.newPage();
});
After(async function () {
if (this.context) await this.context.close();
if (this.browser) await this.browser.close();
});
features/step_definitions/home.js:
const { Given, Then } = require('@cucumber/cucumber');
const assert = require('node:assert/strict');
Given('I open the home page', async function () {
await this.page.goto('https://example.com');
});
Then('the page title should contain {string}', async function (expected) {
const title = await this.page.title();
assert.ok(title.includes(expected), `Expected title to contain "${expected}", got "${title}"`);
});
The example’s hooks create a browser, isolated context, and page for each scenario, then close them. This is a practical lifecycle choice, not a lifecycle Cucumber mandates. Each step is asynchronous and awaits Playwright work, so rejected operations and failed assertions are reported as scenario failures rather than being left running in the background. Cucumber.js supports promise-based asynchronous step definitions and both Cucumber Expressions and regular expressions. Step definition documentation
Share a Playwright page between Cucumber steps
Cucumber-JS creates an isolated World for each scenario. Put the scenario’s browser-related state on that World—as the example does with this.page—so multiple steps in the same scenario can use the same page without sharing it accidentally with other scenarios. Cucumber state
Use regular function expressions for steps and hooks that read or write this. Arrow functions capture their surrounding this and do not receive Cucumber’s World as their function context. If a step does not need World state, it can use an arrow function; when it does, use async function () { ... }.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Choose hooks and browser lifetimes deliberately
Use scenario-level Before and After hooks to acquire and release resources that belong to one scenario. Cucumber runs Before hooks in definition order and After hooks in reverse order. Tag expressions can limit a hook to selected scenarios, which is useful when only some scenarios require special setup. Cucumber.js hooks
Launching a browser per scenario is simple and provides strong isolation, but adds startup and teardown work. A different design can keep a browser process alive longer while still creating a fresh context and page per scenario. Whichever lifecycle you choose, close contexts and browsers reliably, and do not share mutable page state between scenarios unless that behavior is intentional.
Run tagged scenarios and plan for parallel execution
To run only scenarios tagged @smoke, for example, use npx cucumber-js features --require features/support/**/*.js --tags @smoke. A tagged hook can be restricted similarly:
Before({ tags: '@needs-auth' }, async function () {
// Set up scenario-specific authenticated state here.
});
When Cucumber.js runs scenarios in parallel, they execute in workers. Its BeforeAll and AfterAll hooks run once per worker by default—not once for the entire test run. Design server startup, ports, accounts, files, and other shared resources with that scope in mind. Avoid assuming that a process-level resource initialized in one worker is available in another. The Cucumber.js hooks documentation on GitHub’s main branch may describe features that are not in every installed release; check the documentation matching your installed version before relying on version-sensitive hook options. Cucumber.js hooks and parallel execution
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Choose Cucumber.js or Playwright Test
These are alternative runner choices, not two layers that automatically share a test suite. Playwright recommends its own test runner for Node.js. Choose Cucumber.js when executable Gherkin and a BDD workflow are important to the people who write, review, or use the scenarios; then own the integration code for hooks, state, and execution. Choose Playwright Test when its runner and integrated tooling suit the team and Gherkin is not a requirement. Playwright language guidance · Cucumber browser automation
| Decision | Cucumber.js with Playwright | Playwright Test |
|---|---|---|
| Scenario format | Gherkin feature files with matching step definitions | Playwright test files |
| Who runs the scenarios? | Cucumber.js | Playwright’s own runner |
| Who automates the browser? | Playwright library called from support code | Playwright test APIs |
| Integration work | You manage the connection, World state, hooks, and resource lifetimes | Use the Playwright runner and its documented test workflow |
Troubleshoot common failures
-
Cucumber says a step is undefined. The step text does not match a loaded definition, or Cucumber did not discover the support file. Confirm the feature and support paths in the command and that the expression matches the step text. Cucumber expressions and regular expressions are both supported.
-
this.pageis undefined. The setup hook may not have run, the hook may have failed, or the step uses an arrow function and therefore cannot access the World. Use a regular function, check the hook’s tag filter, and ensure the hook assigns the page before the step runs. -
Playwright cannot launch a browser. Install the browser binary for the Playwright package in the project with
npx playwright install chromium, or install the browser(s) your test uses. Consult Playwright browser installation if the environment needs additional setup.Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
-
A scenario hangs or fails during navigation. Make sure the step awaits
page.goto()and that navigation targets a reachable URL. Inspect the actual Playwright error and application readiness conditions; do not hide a rejected promise by starting browser work without awaiting it. -
Scenarios interfere when run in parallel. Check for shared accounts, fixed ports, shared files, or reused browser contexts. Give each scenario isolated browser state and make worker-scoped resources safe for multiple workers.
-
Cleanup runs in an unexpected order. Cucumber executes
Beforehooks in definition order andAfterhooks in reverse. Review hook ordering and make cleanup tolerate partially completed setup.
Or skip the browser setup
If your goal is to capture a website rather than run an interactive Cucumber scenario, ScreenshotNeo provides a screenshot API and MCP server. A single GET request can return an image or PDF; see the API documentation.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchescurl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for free.
Frequently Asked Questions
Can I use TypeScript for Cucumber.js and Playwright?
Yes. Playwright supports TypeScript, but configure Cucumber.js to load your TypeScript support code for the versions and runtime in your project.
Does Playwright Test run Cucumber feature files directly?
No. In this integration, Cucumber.js runs the Gherkin scenarios and Playwright is called from the step definitions.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

