How to debug (protractor) cucumberjs framework 'can not find step definition' problem?

和自甴很熟 提交于 2020-04-18 05:47:29

问题


I have used protractor testing along with cucumberjs framework for a while. I've encountered this 'step definition not found' issue before but it was always a config quick fix until I am playing with this 'cukefarm' library at https://www.npmjs.com/package/cukefarm.

The 'cukefarm' use 'protractor-cucumber-framework' (https://github.com/protractor-cucumber-framework/protractor-cucumber-framework) which I also played before. So I start following 'cukefarm' readme page and start building a hello world project on top of it.

Here's what I know about running (protractor)/cucumberjs testing in a normal manner:

  1. step definition is usually specified in format like below:
  cucumberOpts: 
  {
    // require step definitions
    require: [
      'path/to/step/definitions/**/*.steps.js' 
    ]
  }
  1. cucumberjs will try to regex match feature file step with step definition specified in 'cucumberOpts', and if matched, step definition is found

  2. I don't think the step definition .js file is compiled/syntx-checked first before usage. I tried to add some scrambled characters in the step definition .js file, but not in the function that's used by feature file, it does not stop test from running.

In my new project 'cukefarm_example', I did the following check:

  1. I console log the generated 'cucumberOpts', it points to the correct step definition file path
  "cucumberOpts": {
    "require": [
      "support/*.js",
      "step_definitions/*.js"
    ],
  1. I open the project in IDE that has cucumberjs plugin, and it shows a match between feature file step and step definition .js function

However, i am still getting step definition 'Undefined. Implement with the following snippet:' error.

Warnings:

1) Scenario: Add numbers # features/arithmetic.feature:6 ? Given The calculator is open Undefined. Implement with the following snippet:

     Given('The calculator is open', function () {
       // Write code here that turns the phrase above into concrete actions
       return 'pending';
     });

Is there a systematic way to examine or debug the cucumberjs loading process to see how it's doing the loading of step definition files and how it's finding the step definition .js based on the feature file step?

I am running out of ideas by just checking the configuration by eyes.

来源:https://stackoverflow.com/questions/61179918/how-to-debug-protractor-cucumberjs-framework-can-not-find-step-definition-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!