当我在日食中使用黄瓜和Maven时,它无法识别@ given,@ when,@ then

时间:2019-06-14 07:15:46

标签: eclipse maven cucumber

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test.cucumber</groupId>
  <artifactId>com.test.cucumber</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java8</artifactId>
        <version>1.2.5</version>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.2.5</version>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.2.5</version>
    </dependency>

    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>cucumber-reporting</artifactId>
        <version>3.7.0</version>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>1.2.5</version>
    </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.4.0</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-htmlunit-driver</artifactId>
            <version>2.52.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>21.0</version>
        </dependency>


        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>1.6.2</version>
        </dependency>

    </dependencies>

  
</project>

当我在日食中使用黄瓜和Maven时,它无法识别@ given,@ when,@ then标签。使用的版本是Java1.8,Eclipse氧气,与Eclipse 1.5的Maven集成以及黄瓜Eclipse插件0.23。

如果不使用Maven并且代码运行良好,则可以识别小黄瓜语法。我尝试在pom.xml文件中使用相同版本的依赖项。但是,它仍然没有导入import banana.api.java.en。;。并引发错误。 以下是pom.xml文件供参考。

2 个答案:

答案 0 :(得分:0)

但是您尚未共享pom.xml。但是当我们混合直接和传递依赖时,就会发生这种情况。因此,我们将不会混用直接和传递依赖,特别是它们的版本!这样做可能会导致不可预测的结果。以下是由于错误使用依赖项而导致人们报告的一些错误。

  • 无法解析导入的cumul.api.junit
  • java.lang.NoClassDefFoundError:gherkin / IGherkinDialectProvider
  • 导入cumul.api.DataTable;无法解决

解决方案::您可以添加以下最小黄瓜依赖项集。如果您使用的是info.cukes依赖项,请开始使用io.cucumber依赖项

  • info.cuke是一个非常老的依赖项,最新版本为1.2.5,并且在2016年9月之后不再提供支持,并且

  • io.cucumber是具有2-4.3版本的最新版本,我们可以查看Cucumber团队的所有最新更新

    <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
    </dependency>
    
    <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
    </dependency>
    

答案 1 :(得分:0)

我在POM.XML中尝试了此方法,并且有效:

   <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>groupId</groupId>
        <artifactId>CucumberBasic</artifactId>
        <version>1.0-SNAPSHOT</version>

        <dependencies>
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>4.2.3</version>
            </dependency>

            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-junit</artifactId>
                <version>4.2.3</version>
                <scope>test</scope>
            </dependency>

            <!-- https://mvnrepository.com/artifact/junit/junit -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>

        </dependencies>

    </project>