【问题标题】:Undefined Step definitions in Cucumber JavaCucumber Java 中未定义的步骤定义
【发布时间】:2022-08-19 23:43:30
【问题描述】:

我在 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 运行场景时收到以下错误

步骤未定义 您可以使用下面的 sn-p(s) 来实现此步骤和 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();
}
  • 如果您查看 IDEA 中的运行配置,它是否包含粘合路径?
  • 它不包括任何东西。所以我添加了一个粘合路径为 C:/----/src/test/java/stepDefinitions。这次我收到了这个错误: Exception in thread \"main\" java.lang.IllegalArgumentException: The glue path must have a classpath scheme C:/----/src/test/java/stepDefinitions
  • 尝试一个包名。所以stepDefinitions
  • 我仍然收到第一个错误:步骤未定义。您可以使用下面的 sn-p(s) 来实现此步骤和 4 个其他步骤:
  • 尝试这个。 docs.cucumber.io/docs/guides/10-minute-tutorial 一定要关注它,不要使用 IDEA。然后进行小的更改,直到它与您的项目匹配或停止工作。

标签: java selenium-webdriver intellij-idea cucumber cucumber-java


【解决方案1】:

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

我的跑步班

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-16
    相关资源
    最近更新 更多