Cucumber Java 中未定义的步骤定义

问题描述 投票:0回答:2

我在Login类中添加了登录步骤。但是当我从 Login.feature 文件运行该场景时,我仍然收到未定义的步骤错误。

登录课程

package stepDefinitions;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class Login {

    @Given("I am on the login page")
    public void ı_am_on_the_login_page() {
        // Write code here that turns the phrase above into concrete actions
        throw new io.cucumber.java.PendingException();
    }

    @When("I enter a correct e-mail address")
    public void ı_enter_a_correct_e_mail_address() {
        // Write code here that turns the phrase above into concrete actions
        throw new io.cucumber.java.PendingException();
    }

    @And("I enter a correct password")
    public void ı_enter_a_correct_password() {
        // Write code here that turns the phrase above into concrete actions
        throw new io.cucumber.java.PendingException();
    }

    @And("I click on login button")
    public void ı_click_on_login_button() {
        // Write code here that turns the phrase above into concrete actions
        throw new io.cucumber.java.PendingException();
    }

    @Then("I should be presented with successful login message")
    public void ı_should_be_presented_with_successful_login_message() {
        // Write code here that turns the phrase above into concrete actions
        throw new io.cucumber.java.PendingException();
    }

}

这是我的 Login.feature 文件

Feature: Login page

  Scenario: Successful login test
    Given I am on the login page
    When I enter a correct e-mail address
    And I enter a correct password
    And I click on login button
    Then I should be presented with successful login message

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>org.example</groupId>
    <artifactId>Segmentify_Project</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

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

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

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>7.3.3</version>
        </dependency>
    </dependencies>

</project>

这是项目格式

enter image description here

从 Login.feature 运行场景时收到以下错误

步骤未定义 您可以使用下面的代码片段来实现此步骤和其他 4 个步骤:

@Given("I am on the login page")
public void ı_am_on_the_login_page() {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java.PendingException();
}
java selenium-webdriver intellij-idea cucumber cucumber-java
2个回答
0
投票

我遇到了与此类似的错误。 我尝试了不同的解决方案,例如编辑配置。但是当我创建跑步者类并运行它时,该功能开始正常工作,没有任何问题。

我的跑步班

    @RunWith(Cucumber.class)
@CucumberOptions(features ="C:\\Users\\user1\\Desktop\\Selenium\\com.cucumber\\src\\test\\resources\\features"
,glue = "stepDefinition")
public class testRunner {
}

0
投票

我在使用时遇到了这个问题:JDK 21、selenium-java 4.19.1、cucumber-java 7.16.0。 我已经尝试了我所看到的所有内容,例如指向正确的“步骤”包、创建运行程序类、删除构建并将构建项目添加到“项目之前”部分。但最终解决这个问题的是根据配置的Java版本选择JRE。看图片: Edit Run Configurations

© www.soinside.com 2019 - 2024. All rights reserved.