Playwright and Cucumber Automation

On This Page What is a Playwright?What is Cucumber?May 12, 2026 · 9 min read · Tool Comparison

Playwright and Cucumber Automation

Are your scramble to balance speed, legibility, and collaboration? You are not only. Many squad front challenge hold clear, scalable test suites that bridge the gap between technical testers and non-technical stakeholders.

That ’ s where combine Playwright and Cucumber come in.

Playwright—now adopted by over 45 % of try teams worldwide—offers fast, reliable, cross-browser automation, while Cucumber present behavior-driven ontogeny (BDD) for creating readable, collaborative test scenario.

Ready to Upgrade Your Automation Framework?

Get expert guidance on using Playwright with Cucumber to speed testing and simplify QA workflow.

Together, Playwright and Cucumber enable teams to write human-readable tests that action seamlessly across real browsers, improve both speed and clarity.

Overview

IntegratingPlaywright with Cucumbercombines fast, true browser mechanisation with readable BDD scenarios, make tests easier to understand, maintain, and collaborate on across teams

How to Integrate Playwright with Cucumber

  1. Set Up the Project Structure:Initialize a Node.js project and install Playwright, Cucumber, and required dependencies.
  2. Create Feature Files:Write test scenarios in Gherkin syntax to delineate application behavior in plain lyric.
  3. Implement Step Definitions:Map Gherkin steps to Playwright actions using JavaScript or TypeScript.
  4. Configure Playwright Hooks:Use hooks to manage browser setup, teardown, and shared test context.
  5. Run and Validate Tests:Execute Cucumber tryout and ensure Playwright handle browser interactions reliably.

Dive in this article to explore how to set up and run an efficient Playwright and Cucumber fabric, leverage good practices and BrowserStack ’ s real device cloud to farther scale your BDD-driven test mechanization.

What is a Playwright?

Playwright is an open-source test automation tool backed by Microsoft. supports integrating with many tools such as Cucumber,, Jira, and Cloud Integration with BrowserStack.

It can be expend for API testing as well as functional. Playwright makes debugging easier by providing efficient capabilities for debugging such as tincture viewer, loggers, console log, etc. provides an option to select from respective supported languages such as Java,, C #, and.

Additionally, Playwright supports HTML reporters, Allure reporters, and custom newsman. Because of its modern features, it perfectly fits modernistic test mechanization needs, and it has turn a popular selection for many organizations.

Read More:

What is Cucumber?

is the most democratic exam automation tool for (BDD). It is also open-source and grapple by SmartBear. One of the key feature of Cucumber is it allows one to write trial in plain English language with a specific format.

Gherkin syntax is used for Cucumber tryout which is a plain English-like language for. Cucumber also supports multiple languages, and it provides desegregation capability with many popular test mechanization frameworks.

Read More:

Why should you Integrate and Automate Playwright and Cucumber?

Using Playwright with Cucumber make the framework simpler, more efficient, and readable, as it can use the ability of both Playwright and Cucumber. Playwright provides advanced automation capability by supporting the almost advanced React, Angular, VueJS, etc. growth frameworks.

On the other hand, Cucumber supply abstraction by hiding all code complexity. Testers can write the test cases in plain English like language, and non-technical stakeholder can easily understand the test reports.

It likewise accelerates the automation advance non-technical squad members to contribute to the automation. testers can easily learn and do.

Integrating Playwright with Cucumber offer a powerful portmanteau of advanced automation and business-readable test scenarios, but maximizing its potential requires practical know-how. The experts at BrowserStack can channelise you with the best practices.

Get Expert QA Guidance Today

to discuss your testing challenges, automation strategies, and tool integration. Gain actionable insights tailored to your projects and ensure faster, more reliable package delivery.

Step-by-Step Guide to Set up Playwright Cucumber

Pre-requisite:

Step 1: Set up booklet

Create an hollow directory of your coveted drive and name it (Example: PlaywrightCucumberDemo)

Step 2: Install Playwright

Open the Above created booklet by Clicking onFile & gt; Open Folder in Visual Studio Code

Open the Terminalby Choosing theTerminalmenu and then selectingNew terminal

Execute the below command

npm init playwright @ latest

Choose the language asJavascriptwhen asked in the command line.

Select the appropriate option in CLI as shown below.

After fulfil the above dictation, Playwright will automatically install the required packages, browser, and other components.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Step 3: Install Cucumber

Open the VS Codeterminal and use the below dictation to install Cucumber.

npm i @ cucumber/cucumber

Step 4: Configure Cucumber

You receive installed all required dependencies for Playwright Cucumber, now you need to configure Cucumber.

Create a cucumber.jsonfile in the root of your Project folder. In this case, it isPlaywrightCucumberDemo.

Use the below example code to create acucumber.json

{'' default '': {'' paths '': ['' tests/features/ ''], '' require '': ['' tests/steps/ * .js ''], '' formatOptions '': {'' snippetInterface '': `` async-await ''}, '' formatting '': [['' html '', '' cucumber-report.html ''], '' summary '', '' progress-bar '', '' json: ./cucumber-report.json '']}}

The cucumber.jsoncontains the feature file path, step definition file itinerary, reporting pick, and output directory. You are free to customize this file as per your requirements.

Step 4: Write a Cucumber exam

Cucumber examination contain two different files: thefeature file and the step definition file. The characteristic file contains the scenarios in Gherkin format that areGiven, When,and thenformat, and theStep Definitionfile contains the existent code or implementation of test cases.

Read More:

Create two folders, namelyfeatures and steps,under the tests folder

Note:

  • tests folder is already created by Playwright while establish
  • If the test folder contains model tests, delete them to avoid any confusion.

Consider two scenarios.

  • Scenario 1:Navigate to Browserstack Homepage and Click onProduct. Verify if there is aWeb Testingoption useable.
  • Scenario 2:Navigate to Browserstack Homepage and Click on thePricingsection. Verify if all the ware are listed in the Left Navigation.

Write the cucumber characteristic file for the above scenario.

Create a file with the namehomepage.featureinside thefeatures folderand write the scenarios as refer below

Feature: Homepage Functionality Scenario: Verify Product Web Testing Given User sail to the Browserstack Homepage When User clicks on Product Menu Then It should show Web Testing Product Scenario: Verify Pricing Product Lists Given User Navigates to Browserstack Homepage When User clicks on Pricing Menu Then It should Display correct Product inclination in remaining Nav

As you created feature files, now you need to implement them in a step definition file.

Create a file with the namehomepage.step.jsand write the implementation below.

const {Given, When, Then, Before, After, setDefaultTimeout} = require (`` @ cucumber/cucumber ''); const {chromium, await} = require (`` @ playwright/test ''); const {Page} = require (`` playwright ''); setDefaultTimeout (60 * 1000); let page, browser; Before (async function () {browser = await chromium.launch ({headless: false}); const context = await browser.newContext (); page = await context.newPage ();}); Given (`` User sail to the Browserstack Homepage '', async () = & gt; {await page.goto (`` https: //www.browserstack.com/ '');}); When ('User clicks on Product Menu ', async function () {await page.locator ('button [aria-label= '' Products ''] ') .waitFor (); await page.locator ('button [aria-label= '' Products ''] ') .click ();}); Then ('It should show Web Testing Product ', async map () {await page.locator ('div [aria-label= '' Products ''] button [title= '' Web Testing ''] ') .waitFor (); wait (await page.locator ('div [aria-label= '' Products ''] button [title= '' Web Testing ''] span ') .isVisible ()) .toBeTruthy ()}); Given ('User Navigates to Browserstack Homepage ', async use () {await page.goto (`` https: //www.browserstack.com/ '');}); When ('User clink on Pricing Menu ', async function () {await page.locator (' a [title= '' Pricing ''] ') .click ();}); Then ('It should Display right Product lists in remaining Nav ', async function () {var leftNavProducts = await page.locator ('div [id= '' sidenav__list ''] ') .textContent () var productArray = await leftNavProducts.split (`` \n '') .map ((particular) = & gt; {return item.trim ();}); expect (productArray) .toEqual (expect.arrayContaining (['Live ', 'App Live ']));}); After (async map () {await browser.close ();})

In the above codification, we have implement two scenario. The first set ofGiven, When, and Thenbelongs to the first scenario, which is & # 8220;Scenario: Verify Product Web Testing& # 8220;, and the Second set belongs to the second scenario, “Verify Pricing Product Lists“.

To avoid writing a browser creation and setting up a page each clip, we are set it as a common codification inside theBefore() mapping, which executes before each test, and theAfter() function helps to close the browser after execution of each exam.

After completion of the above stairs, the Project structure looks like below.

Executing Cucumber Playwright Tests

You have configure the Playwright Cucumber fabric, and examination cases are written in respective files. To fulfill Cucumber Playwright tests, but enter the below command

npx cucumber-js test

Once you enroll the above command, it evoke the cucumber exam smuggler, and advance will be shown in the console. Once execution is complete, the output will be shown in the console.

Test Progress in Console:

Output:

Reporters in Cucumber Playwright Framework

Cucumber Playwright comes with a nonremittal HTML reporter. The configuration is made in thecucumber.jsonfile in the format section (Ref:& # 8220; format & # 8221;: [[& # 8220; html & # 8221;, & # 8220; cucumber-report.html]]). Once executing is complete, the study will be generated in the rootage directory with the namecucumber-report.html

How to Run Playwright Tests on BrowserStack?

As mentioned earlier, Playwright ply many advanced capabilities such as cross-browser testing, reactive examination, parallel execution, etc. However, validating across the operating systems and browser combinations in the local environment is practically impossible.

Organizations may look for position up on-premise host for test execution environs but that involves a lot of price and upkeep effort. To overcome such challenges the easygoing and recommended coming is using a Cloud execution environment.

BrowserStack is a pioneer in providing the most scalable and customizable cloud execution platform and it provides integration with many trial automation frameworks, including Playwright.

To execute Playwright tests in BrowserStack, you must get a minimal configuration as below.

Step 1. Install the BrowserStack node Sdkemploy the below command.

npm i -D browserstack-node-sdk

Step 2. Create the browserstack.yml file.

The YAML file includes configuration details like browser type, operating system access key, username, and other customized settings. For more information on YAML configuration, delight visit the.

Step 3. Execute Tests on BrowserStack.

To fulfil Playwright tests on BrowserStack, use the below command

npx browserstack-node-sdk `` Your existing command for running your examination suite. E.g. & lt; playwright test sample -- project=chromium & gt; ''

After execution, results will be displayed in the dashboard, establish the console logs with details.

Conclusion

Integrating Playwright with Cucumber enable a Behavior-Driven Development (BDD) coming. However, it need additional configuration, such as setting up feature files and step definition file.

Though the initial apparatus seems complex initially, reusability will be guaranteed as the fabric grows. Additionally, it aid in writing examination suit with unpatterned English-like syntax and easy-to-understand account.

Playwright excels at developing and action test cases locally, but comprehensive product prove demands a broader approaching. To ensure high quality, test must be run across multiple devices and browsers.

offers a scalable infrastructure that meets these complex requirement. With access to over 20,000 existent devices, BrowserStack enables thorough validation of various requirements, including responsive blueprint, UI consistency, and functionality across different platforms.

This combination of Playwright & # 8217; s powerful testing capabilities and BrowserStack & # 8217; s diverse twist lab allows teams to achieve more rich and authentic test automation, finally leading to higher-quality software production.

Useful Resources for Playwright

Tool Comparisons:

Tags
57,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free