首页 > 解决方案 > 如何解决 Cypress Cucumber 'Step implementation missing for:' 错误?

问题描述

我已经按如下方式设置了 Cypress Cucumber 项目:

我在 package-lock.json 中添加了 "nonGlobalStepDefinitions": true 但仍然找不到步骤。

包-lock.json: https ://paste.ubuntu.com/p/Bww37954Hy/

功能文件: https ://paste.ubuntu.com/p/SxmSkk2Hbv/

步骤定义文件: https ://paste.ubuntu.com/p/k4x4NNypKf/

目录结构:

目录 1

目录 2

错误日志: 错误

TEST BODY
1
When
go to AB site
2
then
{}, function(){}
Error
Step implementation missing for: go to AB site
node_modules/cypress-cucumber-preprocessor/lib/resolveStepDefinition.js:195:1
  193 |       );
  194 |     }
> 195 |     throw new Error(`Step implementation missing for: ${stepText}`);
      | ^
  196 |   },
  197 |   Given: (...args) => {
  198 |     stepDefinitionRegistry.runtime(...args);


Stack:

  at Context.resolveAndRunStepDefinition (node_modules/cypress-cucumber-preprocessor/lib/resolveStepDefinition.js:195:1)
at Context.eval (node_modules/cypress-cucumber-

preprocessor/lib/createTestFromScenario.js:26:1)
From previous event:
    at Context.thenFn (http://localhost:33867/__cypress/runner/cypress_runner.js:155135:24)
    at Context.then (http://localhost:33867/__cypress/runner/cypress_runner.js:155574:22)
    at Context.<anonymous> (http://localhost:33867/__cypress/runner/cypress_runner.js:169891:22)
    at <unknown> (http://localhost:33867/__cypress/runner/cypress_runner.js:169315:16)
From previous event:
    at runCommand (http://localhost:33867/__cypress/runner/cypress_runner.js:169294:9)
    at next (http://localhost:33867/__cypress/runner/cypress_runner.js:169440:15)
    at <unknown> (http://localhost:33867/__cypress/runner/cypress_runner.js:169468:17)
From previous event:
    at next (http://localhost:33867/__cypress/runner/cypress_runner.js:169440:35)
From previous event:
    at Promise.catch.err.name (http://localhost:33867/__cypress/runner/cypress_runner.js:169481:38)
From previous event:
    at run (http://localhost:33867/__cypress/runner/cypress_runner.js:169474:22)
    at $Cy.cy.<computed> [as then] (http://localhost:33867/__cypress/runner/cypress_runner.js:169931:12)
    at Context.runnable.fn (http://localhost:33867/__cypress/runner/cypress_runner.js:170155:22)
    at callFn (http://localhost:33867/__cypress/runner/cypress_runner.js:104227:22)
    at Test.../driver/node_modules/mocha/lib/runnable.js.Runnable.run (http://localhost:33867/__cypress/runner/cypress_runner.js:104214:8)
    at <unknown> (http://localhost:33867/__cypress/runner/cypress_runner.js:175754:29)
From previous event:
    at Object.onRunnableRun (http://localhost:33867/__cypress/runner/cypress_runner.js:175742:18)
    at $Cypress.action (http://localhost:33867/__cypress/runner/cypress_runner.js:166291:29)
    at Test.Runnable.run (http://localhost:33867/__cypress/runner/cypress_runner.js:174128:14)
    at Runner.../driver/node_modules/mocha/lib/runner.js.Runner.runTest (http://localhost:33867/__cypress/runner/cypress_runner.js:104886:11)
    at <unknown> (http://localhost:33867/__cypress/runner/cypress_runner.js:105012:13)
    at next (http://localhost:33867/__cypress/runner/cypress_runner.js:104795:15)
    at <unknown> (http://localhost:33867/__cypress/runner/cypress_runner.js:104805:8)
    at next (http://localhost:33867/__cypress/runner/cypress_runner.js:104707:15)
    at Hook.<anonymous> (http://localhost:33867/__cypress/runner/cypress_runner.js:104768:8)
    at next (http://localhost:33867/__cypress/runner/cypress_runner.js:175675:23)
    at <unknown> (http://localhost:33867/__cypress/runner/cypress_runner.js:175697:12)
From previous event:
    at onNext (http://localhost:33867/__cypress/runner/cypress_runner.js:175694:58)
    at done (http://localhost:33867/__cypress/runner/cypress_runner.js:104167:6)
    at callFn (http://localhost:33867/__cypress/runner/cypress_runner.js:104250:8)
    at Hook.../driver/node_modules/mocha/lib/runnable.js.Runnable.run (http://localhost:33867/__cypress/runner/cypress_runner.js:104214:8)
    at <unknown> (http://localhost:33867/__cypress/runner/cypress_runner.js:175754:29)
From previous event:
    at Object.onRunnableRun (http://localhost:33867/__cypress/runner/cypress_runner.js:175742:18)
    at $Cypress.action (http://localhost:33867/__cypress/runner/cypress_runner.js:166291:29)
    at Hook.Runnable.run (http://localhost:33867/__cypress/runner/cypress_runner.js:174128:14)
    at next (http://localhost:33867/__cypress/runner/cypress_runner.js:104729:11)
    at <unknown> (http://localhost:33867/__cypress/runner/cypress_runner.js:104773:6)
    at timeslice (http://localhost:33867/__cypress/runner/cypress_runner.js:98699:28)

标签: automated-testscucumbercypressbdd

解决方案


您可以尝试将 nonGlobalStepDefinitions 设置为 false 并设置 stepDefinitions 文件夹

 "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": false,
    "stepDefinitions": "cypress/stepsDefinition"
  }

推荐阅读