提问者:小点点

获取“io.cucumber.junit.UndefinedStepException”,同时使用跟踪片段中给出的相同步骤定义


我已经创建了一个cucumber类并试图修改,在此过程中,当我尝试运行时,它会一次又一次地显示“io. cucumber.jinit.Undefined edStepException”。我已经尝试了跟踪片段中显示的步骤,但结果还是一样的。下面是我正在尝试的代码

//feature_file功能:应用程序登录

方案:主页默认登录 给定用户导航到登录页面 当用户使用“abhishek”和密码“abhi234”登录应用程序时,将显示主页 并且显示的对象是“真实的”

场景:主页默认登录给定用户导航到登录页面当用户使用“Amit”和密码“amit345”登录应用程序时,出现主页并且显示的对象为“false”

//步骤定义

public class stepdefination2 {

        @Given("^user navigate to login page$")
        public void navigate() {
            System.out.println("welcome");
            throw new io.cucumber.java.PendingException();
        }
        @When("user login into application with {string} and password {string}")
        public void user_login(String arg1, String arg2) {
            System.out.println(arg1);
            System.out.println(arg2);
            throw new io.cucumber.java.PendingException();
        }
        @Then("^home page appears$")
        public void home_page() {
            System.out.println("homepage");
            throw new io.cucumber.java.PendingException();
        }
        @Then("objects showed are {string}")
        public void objects(String obj) {
            System.out.println("objects appeared");
            throw new io.cucumber.java.PendingException();
        }
}

//跑步者

@RunWith(Cucumber.class)
    @CucumberOptions(
            features =  "src/test/java/nfeature",
            glue = "stepdefination2"
            )
    public class  TestRun2{
        public void success() {
        System.out.println("test run successfully");
    }
    }   

共2个答案

匿名用户

我认为你的@ CucumberOptions选项是不正确的,这就是为什么没有找到步骤

匿名用户

glue = " stepdefination2 "在这里,您需要指定stepdefinations类文件可用的包名。避免给包起相同的名字