29

I am primarily using RubyMine for Cucumber/Ruby, and now, I'm getting my hands on VSCode, with which I'm able to run and debug test cases.

I can't find a way to navigate from feature to step definition. I tried searching for extensions and cucumber-step-mapper doesn't help.

Is there any config which enables navigation from feature to step definition?

Daniel Fintinariu
  • 2,733
  • 1
  • 14
  • 16
Vignesh Paramasivam
  • 2,360
  • 5
  • 26
  • 57

2 Answers2

49

You can install Cucumber (Gherkin) Full Support extension from the VSCode Marketplace:

After install is finished, reload VSCode. Now in order to make it work for Ruby, you need to:

  • Press Ctrl + , to open User Settings

  • Scroll down to Cucumber Auto Complete

  • On the right side you need to modify these settings (you can find 2 examples of how to do this on the extension page). In my case, I added the following:

      "cucumberautocomplete.steps": [
          "features/step_definitions/*.rb"
      ],
      "cucumberautocomplete.syncfeatures": "features/*feature"
    
  • Reload VSCode

  • Open a .feature file and right click any step, you should have Go To Definition and Peek Definition working.

Hope you get it working!

Gaurav Khurana
  • 3,423
  • 2
  • 29
  • 38
Daniel Fintinariu
  • 2,733
  • 1
  • 14
  • 16
  • 4
    Do you see the warning `[cucumberautocomplete] was unable to find step for ...` while hovering over a step in the feature files? If that is the case, then I think the path must be specified in a different way. – Daniel Fintinariu Jul 24 '17 at 14:00
  • 2
    The above did not work for me. I have [cucumberautocomplete] was unable to find step for ... error on every line. I confirmed the folders are correct. – theog Jan 12 '18 at 01:24
  • 2
    sort of partially works for me - some step definitions correctly navigated to - others not ... :-/ – Sam Joseph Mar 12 '18 at 11:19
  • 1
    I have many steps all over the place in my test folder, so would recommend using something like `"cucumberautocomplete.steps": [ "test/**/*.steps.ts" ]` to include all step files. – ViqMontana Jul 03 '18 at 09:10
  • Thanks so much, this helped a lot! – HakunaM Feb 05 '19 at 20:39
  • Had to add `**/` at the beginning of the path as the add-on installed in user profile path – Shabar Jan 15 '20 at 10:37
  • 2
    I had some problems with the paths of features and steps. The reason was that I was skipping the creation of a `.vscode/` folder mentioned in the extension docs. Just in case this can help someone like it did for me: https://stackoverflow.com/a/61610271/7012085 – chick3n0x07CC May 05 '20 at 09:54
  • How to create steps automatically? – Ashok kumar Ganesan Jun 08 '20 at 10:17
  • Awesome! Thanks! , i was facing same problem. Thanks for the Solution – koushick Aug 30 '20 at 16:40
  • 2
    i set up my feature files to be inside cypress/integration/, say cypress/integration/google.feature - having that js file would be in cypress/integration/google/google.js and vscode setting for navigation is: "cucumberautocomplete.steps": [ "cypress/integration/**/*.js", ], – Sasha Bond Sep 17 '20 at 21:49
  • how do you detect nested steps in vscode? I have some steps being called inside other step definitions. Eg `And(/^I've a step inside the step definition$/) do step 'I am calling this step' end` – ReubenTellis Jan 14 '21 at 02:27
2

I have a cucumber with java project and following worked for me:

 "cucumberautocomplete.steps": [
    "**/*Steps.java"
],
"cucumberautocomplete.syncfeatures": "**/*.feature"
Jyoti Prakash
  • 3,921
  • 3
  • 21
  • 24