java - 尝试在 eclipse maven 项目中配置 Cucumber 时,运行程序类中出现错误

标签 java selenium junit cucumber

我正在尝试在 Eclipse 中的 Maven 项目中配置 cucumber 。不幸的是在运行者类别中面临问题。我分别创建了 .feature、stepDefinition.java 和 ,testrunner 文件。我已经尝试了 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>cucumberFramework</groupId>
  <artifactId>cucumberFramework</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>cucumberFramework</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-java</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>1.2.5</version>
            <type>pom</type>
        </dependency>

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

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.5</version>
        </dependency>

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

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>2.12.2</version>
        </dependency>

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

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.5.3</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>


</dependencies> 
</project>

testRunner.java

package runner;
import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions; //shows error as The import cucumber.api cannot be resolved
import cucumber.api.junit.Cucumber;//shows error as The import cucumber.api cannot be resolved


    @RunWith(Cucumber.class)// shows error as Class<Cucumber> cannot be resolved to a type
    @CucumberOptions( //shows error as CucumberOptions cannot be resolved to a type
            features = {"features"} //the path of the feature files
            ,glue={"stepDefinitions"}
            )//the path of the step definition files

    public class testRunner{ 

    }

最佳答案

此问题可能有 3 个可能的原因:

  1. 您可能错过了构建项目的机会。尝试按特定顺序为您的项目运行以下 Maven 命令(运行方式 -> 6 Maven build...-> 在“目标”中添加命令) a) 全新安装 -U b) eclipse :干净 c) eclipse : eclipse
  2. 您在 Eclipse 中的互联网连接可能无法正常工作。此问题请引用:Eclipse cannot connect to internet

  3. 您的 maven“settings.xml”不正确。

关于java - 尝试在 eclipse maven 项目中配置 Cucumber 时,运行程序类中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57444838/

相关文章:

java - 什么是 NullPointerException,我该如何解决?

java - BeanToPropertyValueTransformer 和 commons-collections4

java - 如何在 Eclipse 工作区中解决从一个 gradle 项目到另一 gradle 项目的依赖关系?

python - Selenium 等待元素

maven - Bamboo 无法识别我的 Spring 项目中的测试

java - 在 Hibernate 驱动的 Spring 应用程序中调试 JUnit 测试

java - findViewWithTag 在循环内部使用时给出空对象引用

java - WebDriverException : unknown error: failed to change window state to maximized, 当前状态对于 MacOSX 上的 ChromeDriver v2.43 和 Chrome 70 是正常的

java - 如何解决 "arguments are different"错误 - 单元测试

Python 3,使用请求(库)填写表单返回同一页面 HTML,无需输入参数