当前位置: 首页 > 知识库问答 >
问题:

特性文件中的cucumber-内容帮助不起作用

莫承运
2023-03-14

因此,我一直很难通过Cucumber/Scala集成来降低依赖关系。我终于有了一个简单的步骤定义运行,但当我按control+空格键时,步骤定义列表不会显示在我的功能文件中。但是,当我运行特性文件时,它运行成功。

测试转轮

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")
  }
}

步骤定义文件

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
}
Step 'this pre condition' does not have a matching glue code

以下是一些与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>

共有1个答案

许华清
2023-03-14

因此,我认为问题是依赖关系不匹配以及没有将Junit添加到我的项目路径的综合问题。

这就是我的Test_Steps类现在的样子。我从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 -- ")
  }

}

我的功能文件的内容帮助功能现在工作。

控制台输出

 类似资料: