How to use Playwright in cucumberjs

Manabie Tech-Product Blog
2 min readDec 29, 2021

--

In our previous blog article HERE, we explained why we’re using Cucumber for E2E test at Manabie, and provided a brief understanding about Cucumber.

This time, let’s dive a little bit deeper!

Before we start, let’s cover a brief introduction to Cucumber again, and afterward, about Playwright.

Cucumber

Cucumber is a tool that supports Behaviour-Driven Development(BDD), If you’re new to Behaviour-Driven Development read BDD introduction first.

Cucumberjs

  • is an open-source software testing tool written in Javascript, while the tests are written in Gherkin, a non-technical and human-readable language.

Gherkin Syntax

Gherkin uses a set of special keywords to give structure and meaning to executable specifications. Each keyword is translated to many spoken languages; in this reference we’ll use English.

Each line that isn’t a blank line has to start with a Gherkin keyword, followed by any text you like. The only exceptions are the feature and scenario descriptions.

The primary keywords are:

  • Feature
  • Rule (as of Gherkin 6)
  • Example (or Scenario)
  • Given, When, Then, And, But for steps (or *)
  • Background
  • Scenario Outline (or Scenario Template)
  • Examples (or Scenarios)

There are a few secondary keywords as well:

Playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.

Capabilities

Playwright is built to automate the broad and growing set of web browser capabilities used by Single Page Apps and Progressive Web Apps.

  • Scenarios that span multiple page, domains and iframes
  • Auto-wait for elements to be ready before executing actions (like click, fill)
  • Intercept network activity for stubbing and mocking network requests
  • Emulate mobile devices, geolocation, permissions
  • Support for web components via shadow-piercing selectors
  • Native input events for mouse and keyboard
  • Upload and download files

Getting Started with Cucumber and Playwright Example

Prerequisites and Installations

Prerequisites:

Installations:

Install Cucumber modules with yarn or npm

  • yarn:
  • npm:

Install Playwright

  • yarn
  • npm

Add the following files:

  • features/search_job_openings_at_manabie.feature
  • features/support/world.js
  • features/support/steps.js
  • Run:
  • After run:

Conclusion

Cucumber and Playwright are great frameworks. I hope this article will be of some use to you. Here is source code, thank you.

Curious for more about how we’re tackling testing problems at Manabie? Join us as an Engineer HERE, or follow our blog for future articles.

References

Originally published at https://blog.manabie.io on December 29, 2021.

--

--