Search code examples
scalacucumberbddgherkincucumber-junit

Cucumber - Content Assistance in Feature file not working


So, I've been having a tough time getting the dependencies down with Cucumber/Scala integration. I finally have a simple step definition running, but when I press control + space bar, the list of step definitions do not show up in my feature file. However, when I run the feature file, it runs successfully.

Test Runner

package CucumberTest

import cucumber.api.CucumberOptions
import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith

@RunWith(classOf[Cucumber])
@CucumberOptions(
        features = Array("Feature")
        ,glue= Array("stepDefinition")
        ,plugin = Array ("pretty", "html:target/cucumber/html")
        )
class TestRunner {
  def main(args: Array[String]): Unit = {
    println("Hi")
  }
}

Step Definition file

package stepDefinition

import cucumber.api.scala.{ ScalaDsl, EN }


class Test_Steps extends ScalaDsl with EN{
  Given("""^this pre condition$""") { () =>
    println("YOOOOOOOOO!!!")
  }
  When("""^I do this$""") { () =>
    //// Write code here that turns the phrase above into concrete actions
  }
  Then("""^I can verify that$""") { () =>
    //// Write code here that turns the phrase above into concrete actions
  }
  Then("""^I can also verify that$""") { () =>
    //// Write code here that turns the phrase above into concrete actions
}

This is what my feature looks like. "this pre condition" is highlighted in yellow, indicating that the feature file is not finding the glue code.

When I hover my mouse over the Given statement, I get this message

Step 'this pre condition' does not have a matching glue code

enter image description here

But when I run it, I get this as the output.

Scala Console output

enter image description here

Since YOOOOOOOOO!!! printed in the console, it's seeing my glue code and running successfully, but I don't get a list of step definitions and the phrase "this pre condition" is highlighted yellow.

Does anyone know what the issue could be?

Here are some dependencies relating to cucumber/scala

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.4</version>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-scala_2.11</artifactId>
        <version>1.2.4</version>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.4</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin</artifactId>
        <version>2.12.2</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>1.2.4</version>
    </dependency>
   <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-nop</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>2.11.8</version>
    </dependency>


Solution

  • So I think the issue was a combination on having dependency mismatches as well as not adding Junit to my project path.

    This is what my Test_Steps class looks like now. I imported libraries from Cucumber java api.

    package stepDefinition
    
    //import org.slf4j.LoggerFactory
    import cucumber.api.java.en.Given;
    import cucumber.api.scala._
    import cucumber.api.java.en.Then;
    import cucumber.api.java.en.When;
    import cucumber.api.java8._
    import cucumber.api.scala.{ ScalaDsl, EN }
    import cucumber.runtime.java.StepDefAnnotation
    
    @StepDefAnnotation
    class Test_Steps extends ScalaDsl with EN {
    
      //this works
      @Given("""^this pre condition$""")
      def this_pre_condition() = {
        println("Hello")
      }
    
      @When("""^blah condition$""")
      def when_condition() = {
        println("In the when statement -- ")
      }
    
    }
    

    My feature file's content assistance feature works now.

    enter image description here

    Junit output enter image description here

    Console output

    enter image description here