java CucumberOptions 无法解析为类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46233489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:07:42  来源:igfitidea点击:

CucumberOptions cannot be resolved to a type

javamavenseleniumcucumber

提问by user3548850

In my testrunner class, on using @CucumberOptions, I am getting an error message saying "CucumberOptions cannot be resolved to a type". I am using the latest version of eclipse cucumber dependencies. I have tried every possible way by installing and uninstalling eclipse, by lowering the cucumber dependencies version.

在我的 testrunner 类中,在使用时@CucumberOptions,我收到一条错误消息,指出“CucumberOptions 无法解析为类型”。我正在使用最新版本的 eclipse 黄瓜依赖项。我已经尝试了所有可能的方法,通过安装和卸载 eclipse,降低黄瓜依赖版本。

My runner class is :

我的跑步课程是:

import org.junit.runner.RunWith;
import cucumber.api.junit.*;
import cucumber.api.testng.AbstractTestNGCucumberTests;    

@RunWith(Cucumber.class)
@CucumberOptions(
        // format = {"pretty","html:target/html/" } ,
        features = "src/test/resources", glue = "com.cucumber.bhsibase.party.tests")
public class TestRunner extends AbstractTestNGCucumberTests {
}

And my POM.xml :

还有我的 POM.xml :

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

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

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

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- dependencies added for testng start -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.11</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- dependencies added for testng completed -->

        <!-- dependencies on cucumber jarss -->

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

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>jdom</groupId>
            <artifactId>jdom</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>2.53.0</version>
        </dependency>
        <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>

        <!-- dependencies on log4j jarss -->
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

    </dependencies>
</project>

Please let me know how to proceed ahead with this .

请让我知道如何继续进行。

回答by gary.zhang

I met the same issue. cucumber-java 1.2.2 is working for me.

我遇到了同样的问题。Cucumber-java 1.2.2 对我有用。

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

回答by Arjun Singh

To Resolve this import - import cucumber.api.CucumberOptions;

解决这个导入 - 导入黄瓜.api.CucumberOptions;

add the below maven dependency-

添加以下 maven 依赖项-

info.cukes cucumber-core` 1.2.5

info.cukes 黄瓜核心` 1.2.5

回答by KEERTHI RAM PUVVADA

This option worked out very well.

这个选项效果很好。

  • import cucumber.api.junit.Cucumber; then change the scope of this dependency at Compile level instead of Test. info.cukes cucumber-junit 1.2.5 compile
  • 进口黄瓜.api.junit.Cucumber; 然后在编译级别而不是测试更改此依赖项的范围。info.cukes 黄瓜junit 1.2.5 编译