playwright-bdd: Bug: Error: Requiring @playwright/test second time

Given playwright.config.ts:

import { defineConfig, devices } from '@playwright/test';
import { defineBddConfig } from 'playwright-bdd';

const port = 8080;
const baseURL = `http://localhost:${port}`;

const testDir = defineBddConfig({
  paths: ['playwright/features/**/*.{feature,features}'],
  require: ['playwright/steps/**/*.*'],
});

/**
 * See https://playwright.dev/docs/test-configuration.
 */
export default defineConfig({
  testDir,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 1,
  /* Opt out of parallel tests on CI. */
  fullyParallel: true,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: 'html',
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Base URL to use in actions like `await page.goto('/')`. */
    baseURL,
    headless: true,
    trace: 'on-first-retry',
  },
  workers: 7,

  /* Playwright propose a intern server, it will be launched when the test start */
  webServer: {
    command: 'npm run start',
    port,
    reuseExistingServer: !process.env.CI,
    timeout: 10 * 60 * 1000,
  },
  timeout: 5 * 60 * 1000,
  expect: {
    timeout: 2 * 60 * 1000,
  },
  /* Configure projects for major browsers */
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
      },
    },
    {
      name: 'firefox',
      use: {
        ...devices['Desktop Firefox'],
      },
    },
    {
      name: 'webkit',
      use: {
        ...devices['Desktop Safari'],
      },
    },
  ],
});

When I try to run/debug tests in Visual Code with the “Playwright Test for VSCode” extension

Then If I run in debug mode, it stops with this first error (then there are others if I continue):

Exception has occurred: Error
  at _A (C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:37:3587)
    at Function.statement (C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:37:2847)
    at C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:41:1113
    at C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:1:222
    at C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:65:1678
    at C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:1:222
    at C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:65:38013
    at C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:1:222
    at C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:65:40602
    at C:\Users\xxxxxx\node_modules\playwright\lib\transform\babelBundleImpl.js:1:222

and in the end, I get this error in the test results console:

Error: Requiring @playwright/test second time, 
First:
Error: 
    at Object.<anonymous> (c:\Users\xxxxxx\node_modules\playwright\lib\index.js:77:33)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .js] (c:\Users\xxxxxx\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1013:12)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (c:\Users\xxxxxx\node_modules\playwright\test.js:17:13)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .js] (c:\Users\xxxxxx\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1013:12)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (c:\Users\xxxxxx\node_modules@playwright\test\index.js:17:18)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .js] (c:\Users\xxxxxx\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1013:12)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (c:\Users\xxxxxx\playwright.config.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module.f._compile (c:\Users\xxxxxx\node_modules\playwright\lib\utilsBundleImpl.js:16:994)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .ts] (c:\Users\xxxxxx\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1013:12)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at requireOrImport (c:\Users\xxxxxx\node_modules\playwright\lib\transform\transform.js:182:20)
    at requireOrImportDefaultObject (c:\Users\xxxxxx\node_modules\playwright\lib\common\configLoader.js:126:53)
    at ConfigLoader.loadConfigFile (c:\Users\xxxxxx\node_modules\playwright\lib\common\configLoader.js:99:26)
    at Function.deserialize (c:\Users\xxxxxx\node_modules\playwright\lib\common\configLoader.js:93:51)
    at WorkerMain._loadIfNeeded (c:\Users\xxxxxx\node_modules\playwright\lib\worker\workerMain.js:178:53)
    at WorkerMain.runTestGroup (c:\Users\xxxxxx\node_modules\playwright\lib\worker\workerMain.js:187:18)
    at process.<anonymous> (c:\Users\xxxxxx\node_modules\playwright\lib\common\process.js:96:49)
    at process.emit (node:events:517:28)
    at emit (node:internal/child_process:944:14)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)


Second: 
    at Object.<anonymous> (c:\Users\xxxxxx\node_modules\@playwright\test\index.js:17:18)
    at Object.<anonymous> (c:\Users\xxxxxx\playwright.config.ts:1:1)
    at Object.<anonymous> (C:\Users\xxxxxx\node_modules\playwright\lib\index.js:72:11)
    at Object.<anonymous> (C:\Users\xxxxxx\node_modules\playwright\test.js:17:13)
    at Object.<anonymous> (C:\Users\xxxxxx\node_modules\@playwright\test\index.js:17:18)
    at Object.<anonymous> (C:\Users\xxxxxx\node_modules\playwright-bdd\src\run\bddFixtures.ts:1:1)
    at Object.<anonymous> (C:\Users\xxxxxx\node_modules\playwright-bdd\src\stepDefinitions\createBdd.ts:15:1)
    at Object.<anonymous> (C:\Users\xxxxxx\node_modules\playwright-bdd\src\index.ts:2:1)
    at Object.<anonymous> (C:\Users\xxxxxx\playwright\steps\acquisition.steps.ts:1:1)
    at tryRequire (c:\Users\xxxxxx\node_modules\@cucumber\cucumber\src\try_require.ts:9:12)
    at node_modules\@cucumber\cucumber\src\api\support.ts:27:40
    at getSupportCodeLibrary (c:\Users\xxxxxx\node_modules\@cucumber\cucumber\src\api\support.ts:27:16)
    at loadSupport (c:\Users\xxxxxx\node_modules\@cucumber\cucumber\src\api\load_support.ts:35:57)

But I expect test to run/debug.

Note that the tests are running fine with npx bddgen && npx playwright test.

Isolated demo Hard to make a demo since tests are included in a web react project that I cannot share easily. But I will try if really needed at one point.

Environment

Playwright-bdd environment info:

platform: win32
node: v18.19.0
playwright-bdd: v5.7.1
@playwright/test: v1.41.2
@cucumber/cucumber: v10.3.1
Playwright config file: playwright.config.ts

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve made some investigation and released v6.3.0 that should possibly fix the issue. Could you try it and share the result?

  1. Install latest playwright-bdd
npm i -D playwright-bdd@latest
  1. Change playwright.config.ts to use new steps field instead of require:
const testDir = defineBddConfig({
  paths: ['playwright/features/**/*.feature'],
-  require: ['playwright/steps/**'],
+  steps: ['playwright/steps/**'],
});
  1. Run tests as usual via CLI and via VSCode extension

This error should gone as since v7 playwright-bdd does not use Cucumber for requiring steps. Feel free to reopen in case of any issues.

After https://github.com/vitalets/playwright-bdd/issues/136 this issue should gone, b/c there will be single place of requiring Playwright.

When I run test in MS VSC using Test Explorer I got following output:

Running 1 test using 1 worker

  1. [chromium] › features\homepage.feature.spec.js:6:7 › Playwright Home Page › Check title ───────
Error: Requiring @playwright/test second time, 
First:
Error: 

   at ..\playwright.config.ts:1

> 1 | import { defineConfig, devices } from '@playwright/test';
    | ^
  2 | import { defineBddConfig, cucumberReporter } from 'playwright-bdd';
  3 |
  4 | const testDir = defineBddConfig({

    at Object.<anonymous> (c:\rep\playwright-bdd-example\node_modules\playwright\lib\index.js:69:33)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .js] (c:\rep\playwright-bdd-example\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (c:\rep\playwright-bdd-example\node_modules\playwright\test.js:17:13)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .js] (c:\rep\playwright-bdd-example\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (c:\rep\playwright-bdd-example\node_modules\@playwright\test\index.js:17:18)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .js] (c:\rep\playwright-bdd-example\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (c:\rep\playwright-bdd-example\playwright.config.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module.f._compile (c:\rep\playwright-bdd-example\node_modules\playwright\lib\utilsBundleImpl.js:16:994)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.i.<computed>.ut._extensions.<computed> [as .ts] (c:\rep\playwright-bdd-example\node_modules\playwright\lib\utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at requireOrImport (c:\rep\playwright-bdd-example\node_modules\playwright\lib\transform\transform.js:193:20)
    at loadUserConfig (c:\rep\playwright-bdd-example\node_modules\playwright\lib\common\configLoader.js:96:83)
    at loadConfig (c:\rep\playwright-bdd-example\node_modules\playwright\lib\common\configLoader.js:101:28)
    at deserializeConfig (c:\rep\playwright-bdd-example\node_modules\playwright\lib\common\configLoader.js:91:24)
    at WorkerMain._loadIfNeeded (c:\rep\playwright-bdd-example\node_modules\playwright\lib\worker\workerMain.js:188:62)
    at WorkerMain.runTestGroup (c:\rep\playwright-bdd-example\node_modules\playwright\lib\worker\workerMain.js:197:18)
    at process.<anonymous> (c:\rep\playwright-bdd-example\node_modules\playwright\lib\common\process.js:96:49)
    at process.emit (node:events:517:28)
    at emit (node:internal/child_process:944:14)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Second: 
    at Object.<anonymous> (c:\rep\playwright-bdd-example\node_modules\@playwright\test\index.js:17:18)
    at Object.<anonymous> (c:\rep\playwright-bdd-example\playwright.config.ts:1:1)
    at Object.<anonymous> (C:\rep\playwright-bdd-example\node_modules\playwright\lib\index.js:64:11)
    at Object.<anonymous> (C:\rep\playwright-bdd-example\node_modules\playwright\test.js:17:13)
    at Object.<anonymous> (C:\rep\playwright-bdd-example\node_modules\@playwright\test\index.js:17:18)
    at Object.<anonymous> (C:\rep\playwright-bdd-example\node_modules\playwright-bdd\src\run\bddFixtures.ts:1:1)
    at Object.<anonymous> (C:\rep\playwright-bdd-example\node_modules\playwright-bdd\src\steps\createBdd.ts:15:1)
    at Object.<anonymous> (C:\rep\playwright-bdd-example\node_modules\playwright-bdd\src\index.ts:2:1)
    at Object.<anonymous> (C:\rep\playwright-bdd-example\steps\fixtures.ts:1:1)
    at tryRequire (c:\rep\playwright-bdd-example\node_modules\@cucumber\cucumber\src\try_require.ts:9:12)
    at c:\rep\playwright-bdd-example\node_modules\@cucumber\cucumber\src\api\support.ts:27:40
    at getSupportCodeLibrary (c:\rep\playwright-bdd-example\node_modules\@cucumber\cucumber\src\api\support.ts:27:16)
    at loadSupport (c:\rep\playwright-bdd-example\node_modules\@cucumber\cucumber\src\api\load_support.ts:35:57)

Error in reporter Error: __bddData annotation is not found for test “Check title”. at TestCaseRun.extractBddData (c:\rep\playwright-bdd-example\node_modules\playwright-bdd\src\reporter\cucumber\messagesBuilder\TestCaseRun.ts:77:13) at new TestCaseRun (c:\rep\playwright-bdd-example\node_modules\playwright-bdd\src\reporter\cucumber\messagesBuilder\TestCaseRun.ts:53:25) at MessagesBuilder.onTestEnd (c:\rep\playwright-bdd-example\node_modules\playwright-bdd\src\reporter\cucumber\messagesBuilder\Builder.ts:58:25) at Object.onTestEnd (c:\rep\playwright-bdd-example\node_modules\playwright-bdd\src\reporter\cucumber\messagesBuilder\index.ts:21:34) at CucumberReporterAdapter.onTestEnd (c:\rep\playwright-bdd-example\node_modules\playwright-bdd\src\reporter\cucumber\index.ts:56:29) at ReporterV2Wrapper.onTestEnd (c:\rep\playwright-bdd-example\node_modules\playwright\lib\reporters\reporterV2.js:87:150) at c:\rep\playwright-bdd-example\node_modules\playwright\lib\reporters\multiplexer.js:47:65 at wrap (c:\rep\playwright-bdd-example\node_modules\playwright\lib\reporters\multiplexer.js:86:5) at Multiplexer.onTestEnd (c:\rep\playwright-bdd-example\node_modules\playwright\lib\reporters\multiplexer.js:47:45) at InternalReporter.onTestEnd (c:\rep\playwright-bdd-example\node_modules\playwright\lib\reporters\internalReporter.js:62:20) at JobDispatcher._reportTestEnd (c:\rep\playwright-bdd-example\node_modules\playwright\lib\runner\dispatcher.js:524:20) at JobDispatcher._onTestEnd (c:\rep\playwright-bdd-example\node_modules\playwright\lib\runner\dispatcher.js:290:10) at WorkerHost.emit (node:events:517:28) at ChildProcess.<anonymous> (c:\rep\playwright-bdd-example\node_modules\playwright\lib\runner\processHost.js:105:16) at ChildProcess.emit (node:events:517:28) at emit (node:internal/child_process:944:14) 1 failed [chromium] › features\homepage.feature.spec.js:6:7 › Playwright Home Page › Check title ────────

Same issue with the steps above. Unable to execute the test from the test runner.

Thanks for sharing this, I will check.