5

我一起使用 Cucumber-JVM 和 Selenium WebDriver。我在 Eclipse 中有一个 Maven 项目,pom.xml 文件的依赖关系如下:

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.2</version>
    <scope>test</scope>
</dependency>

RunCukesTest.java 文件的内容是:

import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber-htmlreport","json-pretty:target/cucumber-report.json"})
public class RunCukesTest {
}

我在以下代码行中收到错误:

import cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber-htmlreport","json-pretty:target/cucumber-report.json"})

但是当我使用 1.0.14 版本时,它运行良好。最新版本有什么问题?

4

7 回答 7

9

@Cucumber.Options推荐使用@CucumberOptions_

@CucumberOptions(
    format = "pretty",
    features = "//refer to Feature file"  
)

希望这可以帮助你

于 2015-07-08T09:30:06.250 回答
5

注释已更改为@CucumberOptions

我认为在这个黄瓜版本中json-pretty已经改变了。json

这应该有效:

@CucumberOptions(
      format = {"pretty", "html:target/cucumber-htmlreport","json:target/cucumber-report.json"}
)

此外,根据cucumber-jvm 规范,不推荐使用格式。您应该替换为plugin. 这也应该有效:

plugin = {"pretty", "html:target/cucumber-htmlreport","json:target/cucumber-report.json"}

希望能帮助到你

于 2015-07-08T09:29:56.137 回答
3

黄瓜 1.2.2

<cucumber.version>1.2.2</cucumber.version>
....
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
....

这是一个示例工作测试:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features/myfeature.feature", tags = "@Mytag", plugin = {"pretty", "html:target/cucumber"})
public class MYAcceptanceTest {

}

请注意导入cucumber.api.junit.Cucumber不是,cucumber.junit.Cucumber您需要为黄瓜选项添加导入。该选项的刻板印象@CucumberOptions@Cucumber.Options

于 2015-07-08T09:30:47.017 回答
2

@CucumberOptions替换@Cucumber.Options 并用插件格式化

@CucumberOptions(plugin = {"pretty", "html:target/cucumber-htmlreport","json-pretty:target/cucumber-report.json"})
public class RunCukesTest {
}
于 2017-11-07T10:13:12.117 回答
1

您可以尝试将 RunCukesTest.java 文件和您的 Feature 文件放在同一个文件夹或包中。

于 2016-10-15T22:27:11.733 回答
1

Cucumber 版本现已更新至 2.0.1 版本。代替

<groupId>info.cukes</groupId>

<groupId>io.cucumber</groupId>
于 2017-11-09T11:55:16.967 回答
0

通过添加以下依赖项,上述问题得到解决

请列出 POM 中添加的依赖项

<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>FirstBBDApp</groupId>
    <artifactId>FirstBBDApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>FirstBBDApp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>1.2.5</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-html</artifactId>
            <version>0.2.6</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.cobertura</groupId>
            <artifactId>cobertura</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>2.12.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/gherkin-jvm-deps -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin-jvm-deps</artifactId>
            <version>1.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>2.0.2-beta</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.7.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit-dep -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit-dep</artifactId>
            <version>4.11</version>
            <type>pom</type>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.14.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.6</version>
            <scope>system</scope>
            <systemPath>C:\Program Files\Java\jdk1.8.0_202\lib\tools.jar</systemPath>
        </dependency>
    </dependencies>
</project>
于 2019-02-05T09:30:56.563 回答