Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellij not recognizing these groovy steps #20

Open
rahgir opened this issue Jul 17, 2020 · 17 comments
Open

Intellij not recognizing these groovy steps #20

rahgir opened this issue Jul 17, 2020 · 17 comments

Comments

@rahgir
Copy link

rahgir commented Jul 17, 2020

Hi,
Are you observing any issue related to Intellij showing steps as Undefined.?
I upgraded my cucumber-groovy , cucumber-core & cucumber-junit to 5.1.3 and observing this problem. Earlier I was using cucumber 1.25 and everything was working fine.
Any pointers will be great help.

Thanks!

@rahgir
Copy link
Author

rahgir commented Jul 17, 2020

Hello! My company hasn't yet migrated to cucumber-jvm-groovy 5.X just yet, but we are on 4.X. This shows up every now and then for us, and here is what we do to fix this:

  1. Make sure you have installed the IntelliJ plugins "Cucumber for Java" and "Cucumber for Groovy"

Thanks for the reply. I have both these plugins and I uninstalled 'substeps' plugin as well. Still I face this issue.

@ice1080
Copy link

ice1080 commented Jul 17, 2020

Hello! My company hasn't yet migrated to cucumber-jvm-groovy 5.X just yet, but we are on 4.X. This shows up every now and then for us, and here is what we do to fix this:

  1. Make sure you have installed the IntelliJ plugins "Cucumber for Java", "Cucumber for Groovy", and "Gherkin".
  2. Open up Project Structure window, go to the Modules left tab, click on your project, click on the sources tab
  3. Find the folder containing your steps, mark the directory as Test Resources (ours was src/test/groovy/steps)
  4. Find the folder containing your features, mark the directory as Test Resources (ours was src/test/resources)
  5. For us, we had to also do the following. These may or may not be required depending on your project setup
    1. Mark src/test/groovy as Test Sources
    2. Mark src/main/groovy as Sources
    3. Mark src/main/java as Sources (if applicable)
    4. Mark src/main/resources as Resources
  6. Invalidate caches and restart (if changes didn't already work)
  7. If after indexing that still did not work, then follow 2-6 again, but first unmark each folder as what was mentioned above and then mark it.

Those are the things that worked for us, hope these help.

@rahgir
Copy link
Author

rahgir commented Jul 17, 2020

@ice1080 : Thanks again. I already tried these steps as we used to work with cucumber 1.25. This is definitely looking like bug in Intellij. I have posted it on other sites as well. Here is the link: https://stackoverflow.com/questions/62956227/intellij-not-able-to-identify-cucumber-5-groovy-steps

@ice1080
Copy link

ice1080 commented Jul 17, 2020

@ice1080 : Thanks again. I already tried these steps as we used to work with cucumber 1.25. This is definitely looking like bug in Intellij. I have posted it on other sites as well. Here is the link: https://stackoverflow.com/questions/62956227/intellij-not-able-to-identify-cucumber-5-groovy-steps

Step 7 was the one that worked 90% of the time and definitely the most important of all of the above steps. Unmarking them all and then remarking didn't work?

@rahgir
Copy link
Author

rahgir commented Jul 17, 2020

@ice1080 : Hey after changing cucumber-groovy to 4.7.1 & cucumber-core & cucumber-junit to 4.8.1, I am still facing this issue.
which version you are using in your proj ? Dont know if I am missing something very basic. Intellij I am using is 2020.1.3.

@ice1080
Copy link

ice1080 commented Jul 17, 2020

@ice1080 : Hey after changing cucumber-groovy to 4.7.1 & cucumber-core & cucumber-junit to 4.8.1, I am still facing this issue.
which version you are using in your proj ? Dont know if I am missing something very basic. Intellij I am using is 2020.1.3.

We are using cucumber-groovy, cucumber-junit, and cucumber-spring, all versions 4.5.4, and cucumber-reporting 4.7.0. We had some different, unrelated issues on 4.7+ so went back to 4.2.0 and then were able to get up to 4.5.4

@rahgir
Copy link
Author

rahgir commented Jul 17, 2020

4.7.0

@ice1080 : Hey ! I identified my issue. Thing is I messed up with syntax of Groovy and Java and overlooked the syntax of Groovy steps. After correcting it as mentioned in this project, it worked. I upgraded to cucumber-groovy to 4.7.4 & cucumber-core, cucumber-junit to 4.8.1. It is working as expected. Also tried upgrading to 5.1.3 but it was not working. One breaking issue I observed after moving from 1.2.5 to 4.8.1 is @field vars used in my Scripts. I am also trying the version you mentioned above. Thanks much buddy 🥇

@djangofan
Copy link

Probably would go a long way for this project to create a "cucumber-groovy" plugin for IntelliJ-IDEA that would setup the project structure and source folders auto-magically.

@cheparsky
Copy link

Anyone working on this issue? I want to use version 6.1.2 and it still don't work

I noticed that when we use the proposed:
import io.cucumber.groovy.EN this.metaClass.mixin(EN)

IntelliJ don't recognise step, but when we use old solution:
this.metaClass.mixin(cucumber.api.groovy.EN)

IntelliJ recognise steps. Or it recognises because we actually nothing pass to mixin method.

I think the problem lies somewhere in EN class

@glibas
Copy link
Member

glibas commented Apr 28, 2021

Hi @cheparsky ,

Have you got a reproducible snippet/project, it'll help us debug the issue you are seeing.

Also please let us know Intellij version together with plugins installed.

@janainaiacia
Copy link

janainaiacia commented Jul 12, 2021

Hi, I'm having issues with the parameters in a project test

    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testImplementation group: 'junit', name: 'junit', version: '4.12'

    //Cucumber
    testImplementation group: 'io.cucumber', name:'cucumber-groovy', version: '6.10.4'
    testImplementation group: 'io.cucumber', name:'cucumber-junit', version: '6.10.4'
    testImplementation group: 'io.cucumber', name:'cucumber-expressions', version: '12.1.1'
Feature File
Feature: Is it Friday yet?
  Everybody wants to know when it's Friday

  Scenario: Sunday isn't Friday
    Given today is "Sunday"
    When I ask whether it is Friday yet
    Then I should be told "Nope"

Groovy Script

package steps

import static org.junit.Assert.*;
import io.cucumber.groovy.EN
import io.cucumber.groovy.Hooks

metaClass.mixin(EN)
this.metaClass.mixin(Hooks)

Before(){
    def today
}

Given("today is {string}") { String string ->
    // Write code here that turns the phrase above into concrete actions
    today = "input"
}

When("I ask whether it is Friday yet") { ->
    // Write code here that turns the phrase above into concrete actions
    today = "Nope"
}
Then("I should be told {string}") { String input ->
    // Write code here that turns the phrase above into concrete actions
    assertEquals(today, input)
}

When I run the test, I have this error:
image

Any clue about it?

@assilzm
Copy link

assilzm commented Dec 9, 2021

Hi, I'm having issues with the parameters in a project test

    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testImplementation group: 'junit', name: 'junit', version: '4.12'

    //Cucumber
    testImplementation group: 'io.cucumber', name:'cucumber-groovy', version: '6.10.4'
    testImplementation group: 'io.cucumber', name:'cucumber-junit', version: '6.10.4'
    testImplementation group: 'io.cucumber', name:'cucumber-expressions', version: '12.1.1'
Feature File
Feature: Is it Friday yet?
 Everybody wants to know when it's Friday

 Scenario: Sunday isn't Friday
   Given today is "Sunday"
   When I ask whether it is Friday yet
   Then I should be told "Nope"

Groovy Script

package steps

import static org.junit.Assert.*;
import io.cucumber.groovy.EN
import io.cucumber.groovy.Hooks

metaClass.mixin(EN)
this.metaClass.mixin(Hooks)

Before(){
    def today
}

Given("today is {string}") { String string ->
    // Write code here that turns the phrase above into concrete actions
    today = "input"
}

When("I ask whether it is Friday yet") { ->
    // Write code here that turns the phrase above into concrete actions
    today = "Nope"
}
Then("I should be told {string}") { String input ->
    // Write code here that turns the phrase above into concrete actions
    assertEquals(today, input)
}

When I run the test, I have this error: image

Any clue about it?

I have the same problem.But if I add ^$ to the content. It works.

@ghost
Copy link

ghost commented Dec 9, 2021

@janainaiacia and @assilzm, when we define our groovy steps we do so like this:

Given(~'^today is "([^"]*)"$') { String input ->
  println input
}

The ~ before tells groovy that it's a regex string. The starting ^ and ending $ tell it that there should be no other text in the step. Then the "([^"]*)" tells it that there is a String parameter in the double quotes.
I'll also mention that we put our cucumber definitions in an implementation block instead of testImplementation. That's primarily because we're using cucumber with selenium and it complains if we don't.
Hopefully that's helpful. Cheers.

@cheparsky
Copy link

Hi @icdt-ihudson , last version 6.10.4 is working fine for me. But I have problem with step definitions; when i use (~'^step$') all works fine, and when I want use@ParameterType step arguments using ('step') IntelliJ doesn't recognize it in feature file and stepsDefs are not clickable

@ghost
Copy link

ghost commented Dec 8, 2022

Hi @cheparsky. I'm still on version 5.1.3, but unfortunately I've never used the @ParameterType definition so can't help with that. Is there a reason you need that type of step definition instead of using the above format? Not saying it shouldn't work, just wanting to understand it.
I'm not a contributor to the project, just a user; but perhaps tagging one of the contributors might get them to figure out what's going on with the @ParameterType?

@cheparsky
Copy link

@icdt-ihudson yes, I need this another format, only this format works with @ParameterType.

@glibas @mpkorstanje do you know smth about this error, can you fix it? Or this problem more related to Intellij itself?

@mpkorstanje
Copy link
Contributor

@cheparsky in #20 (comment) you were asked to provided a minimal reproducer and additional information. You've not provided that information so it would be hard for anyone to help you.

Anyway, I wouldn't be able to tell you much more, and if I think @glibas is currently fighting in a war. You may have to investigate this in more detail yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants