Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@qavajs/playwright-runner-adapter

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qavajs/playwright-runner-adapter

adapter for playwright test runner

latest
Source
npmnpm
Version
2.3.3
Version published
Maintainers
1
Created
Source

npm version

@qavajs/playwright-runner-adapter

Adapter to run Cucumber BDD tests via the Playwright test runner. Write feature files in Gherkin, execute them with Playwright's parallelism, reporting, and fixture system.

Table of Contents

Installation

npm install @qavajs/playwright-runner-adapter

Quick Start

1. Create a Cucumber config file

// cucumber.config.ts
import { defineConfig } from '@qavajs/playwright-runner-adapter';

export default defineConfig({
    paths: ['test/features/**/*.feature'],
    require: ['test/step_definitions/**/*.ts']
});

2. Point Playwright at it

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
    testMatch: 'cucumber.config.ts'
});

3. Run tests

npx playwright test

Configuration Reference

defineConfig accepts standard Cucumber options:

OptionTypeDescription
pathsstring[]Glob patterns for .feature files
requirestring[]Glob patterns for step definition files (CommonJS require)
importstring[]Glob patterns for step definition files (ESM import)
requireModulesstring[]Modules to require before step definitions (e.g. ts-node/register)
// cucumber.config.ts
import { defineConfig } from '@qavajs/playwright-runner-adapter';

export default defineConfig({
    paths: ['test/features/**/*.feature'],
    require: ['test/step_definitions/**/*.ts'],
    requireModules: [],
});

World Classes

TestWorld

Base world class with Cucumber lifecycle methods and Playwright's test and expect.

import { TestWorld } from '@qavajs/playwright-runner-adapter';
PropertyTypeDescription
testTestTypePlaywright test instance (default or custom)
expectExpectTypePlaywright expect instance (default or custom)
attachfunctionAttach files/data to the test report
logfunctionLog data to console
parametersstringCucumber world parameters
configanyCucumber config object
supportCodeLibraryanyAccess to the loaded support code library

executeStep(text, extraParam?) — programmatically invoke a step by its text:

When('composite step', async function (this: PlaywrightWorld) {
    await this.executeStep('I open the home page');
    await this.executeStep('I click "Login"');
});

PlaywrightWorld

Extends TestWorld with Playwright browser fixtures pre-wired.

import { PlaywrightWorld } from '@qavajs/playwright-runner-adapter';
PropertyTypeDescription
pagePageCurrent Playwright page
contextBrowserContextCurrent browser context
browserBrowserBrowser instance
requestAPIRequestContextAPI request context

Use PlaywrightWorld (or a class extending it) as your world constructor when you need browser access in step definitions:

import { setWorldConstructor, PlaywrightWorld } from '@qavajs/playwright-runner-adapter';

setWorldConstructor(PlaywrightWorld);

Given('I open {string}', async function (this: PlaywrightWorld, url: string) {
    await this.page.goto(url);
});

Custom World

Extend PlaywrightWorld to add custom fixtures or override test/expect.

Connecting custom Playwright fixtures:

import { test as base, expect as baseExpect, Page } from '@playwright/test';
import { setWorldConstructor, PlaywrightWorld } from '@qavajs/playwright-runner-adapter';

type MyFixtures = {
    settingsPage: SettingsPage;
};

const customTest = base.extend<MyFixtures>({
    settingsPage: async ({ page }, use) => {
        await use(new SettingsPage(page));
    },
});

const customExpect = baseExpect.extend({
    async toBeValid(received) {
        // custom matcher implementation
    },
});

class MyWorld extends PlaywrightWorld {
    settingsPage!: SettingsPage;

    // Override test and expect with extended versions
    test = customTest;
    expect = customExpect;

    // init is called with all fixtures — map them to world properties here
    init = ({ page, settingsPage }: { page: Page; settingsPage: SettingsPage }) => {
        this.page = page;
        this.settingsPage = settingsPage;
    };
}

setWorldConstructor(MyWorld);

The init function receives Playwright fixtures as its argument. Its signature determines which fixtures Playwright injects — list only the fixtures you need.

Hooks

All standard Cucumber hooks are supported. Hooks run as named Playwright steps and appear in the trace viewer and HTML report.

import {
    Before, After,
    BeforeStep, AfterStep,
    BeforeAll, AfterAll,
    ITestCaseHookParameter,
    ITestStepHookParameter,
} from '@qavajs/playwright-runner-adapter';

// Runs before each scenario
Before(async function (this: PlaywrightWorld, { pickle }: ITestCaseHookParameter) {
    console.log('Starting:', pickle.name);
});

// Runs after each scenario — result is available
After(async function (this: PlaywrightWorld, { result }: ITestCaseHookParameter) {
    if (result?.status === 'FAILED') {
        await this.page.screenshot({ path: 'failure.png' });
    }
});

// Runs before/after each step
BeforeStep(async function (this: PlaywrightWorld, { pickleStep }: ITestStepHookParameter) {
    console.log('Step:', pickleStep.text);
});

AfterStep(async function (this: PlaywrightWorld, { result }: ITestStepHookParameter) {
    console.log('Step status:', result?.status);
});

// Runs once per worker process
BeforeAll(async function () {
    // setup shared state
});

AfterAll(async function () {
    // teardown shared state
});

Named hooks — supply a name to make the hook identifiable in reports:

Before({ name: 'Authenticate user' }, async function (this: PlaywrightWorld) {
    // ...
});

Scoped hooks — use a tag expression to run hooks only for matching scenarios:

Before({ tags: '@needsAuth' }, async function (this: PlaywrightWorld) {
    // runs only for scenarios tagged @needsAuth
});

Step Arguments

Data Tables:

When I submit the form
  | field    | value   |
  | username | alice   |
  | password | secret  |
import { When, DataTable } from '@qavajs/playwright-runner-adapter';

When('I submit the form', async function (this: PlaywrightWorld, table: DataTable) {
    const rows = table.hashes(); // [{ field: 'username', value: 'alice' }, ...]
});

Doc Strings:

When I set the body
  """
  {"key": "value"}
  """
When('I set the body', async function (this: PlaywrightWorld, body: string) {
    // body === '{"key": "value"}'
});

Template Steps

Template composes a step out of other existing steps, eliminating the need for custom step implementations for common sequences.

import { When, Template } from '@qavajs/playwright-runner-adapter';

When('I log in as {string}', Template((username: string) => `
    I fill in "username" with "${username}"
    I fill in "password" with "secret"
    I click "Submit"
`));

Each non-empty line in the returned string is executed as an individual step against the current world. Steps run sequentially; a failure stops the sequence.

Filtering Tests

Tag Expressions

Use tags to translate a Cucumber tag expression into a Playwright grep pattern:

// playwright.config.ts
import { defineConfig } from '@playwright/test';
import { tags } from '@qavajs/playwright-runner-adapter';

export default defineConfig({
    grep: tags('@smoke and not @slow'),
});

Supports the full Cucumber tag expression syntax: and, or, not, parentheses.

Predicate Filter

Use filter when you need arbitrary logic to select scenarios:

import { defineConfig } from '@playwright/test';
import { filter } from '@qavajs/playwright-runner-adapter';

export default defineConfig({
    grep: filter(name => name.includes('login')),
});

The predicate receives the full test name (feature + scenario title + tags) and should return true to include the test.

Parallelism

Playwright projects let you run subsets of scenarios in parallel or serially:

// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
import { tags } from '@qavajs/playwright-runner-adapter';

export default defineConfig({
    testMatch: 'cucumber.config.ts',
    projects: [
        {
            name: 'parallel',
            grep: tags('not @serial'),
            use: devices['Desktop Chrome'],
            fullyParallel: true,
        },
        {
            name: 'serial',
            grep: tags('@serial'),
            use: devices['Desktop Chrome'],
            fullyParallel: false,
        },
    ],
});

Tag scenarios that must run serially with @serial (or any tag of your choice) and keep everything else fully parallel.

To get the current worker index inside a step, use this.test.info().parallelIndex.

JavaScript / CommonJS Support

If your step definitions are plain JavaScript (.js), import from the ./js entrypoint to avoid TypeScript overhead:

// cucumber.config.js
const { defineConfig } = require('@qavajs/playwright-runner-adapter/js');

module.exports = defineConfig({
    paths: ['test/features/**/*.feature'],
    require: ['test/step_definitions/**/*.js'],
});
// step_definitions/steps.js
const { Given, When, Then, PlaywrightWorld } = require('@qavajs/playwright-runner-adapter/js');

Limitations

  • ES modules — not supported for Node.js < 22 (where experimental ESM require is available). Use CommonJS or TypeScript with ts-node.
  • setParallelCanAssign — not supported. Use Playwright projects with fullyParallel to control parallelism.
  • CUCUMBER_PARALLEL / CUCUMBER_TOTAL_WORKERS / CUCUMBER_WORKER_ID — not supported. Use this.test.info().parallelIndex and this.test.info().workerIndex instead.

Keywords

test

FAQs

Package last updated on 11 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts