我正在使用 Cucumber Selenium 开始我的测试自动化项目。我使用 JUnit 运行了我的测试运行程序——它通过了功能和场景行,但跳过了步骤(给定、何时、然后)。我在每个步骤上都放置了打印行命令,只是为了查看它是否会运行这些步骤。有人可以帮我解决这个问题吗?
这是我的步骤定义:
package stepDefinitions;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;
public class StationCheckStepDef {
@Given("^User Opens the Station Check Application$")
public void user_Opens_the_Station_Check_Application() {
// Write code here that turns the phrase above into concrete actions
System.out.println("This step opens the Station Check app");
}
@When("^The Transmission Date is within six months$")
public void the_Transmission_Date_is_within_months() throws Exception {
System.out.println("This step verifies the default Transmission date range");
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
@Then("^Verify the list of station checks displayed in the page$")
public void verify_the_list_of_station_checks_displayed_in_the_page() throws Exception{
System.out.println("This step verifies the list of displayed checks");
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
这是我的测试运行程序
package testrunner;
import junit.framework.*;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features = {"src/test/resources/features/StationCheck.feature"},
glue = {"src/test/java/stepDefinitions"},
tags= {"@smoke"},
plugin= {"pretty", "json:target/cucumber.json"}
)
public class TestRunner{
}
这是 JUnit run 的结果
控制台输出:
Feature: Verify Initial List of Station Checks
@smoke
Scenario: Verify active checks are displayed on Initial Loading of the application [90m# src/test/resources/features/StationCheck.feature:4[0m
[33mGiven [0m[33mUser Opens the Station Check Application[0m
[33mWhen [0m[33mThe Transmission Date is within six months[0m
[33mThen [0m[33mVerify the list of station checks displayed in the page[0m
1 Scenarios ([33m1 undefined[0m)
3 Steps ([33m3 undefined[0m)
0m0.000s
You can implement missing steps with the snippets below:
@Given("^User Opens the Station Check Application$")
public void user_Opens_the_Station_Check_Application() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^The Transmission Date is within six months$")
public void the_Transmission_Date_is_within_six_months() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^Verify the list of station checks displayed in the page$")
public void verify_the_list_of_station_checks_displayed_in_the_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
功能文件:
Feature: Verify Initial List of Station Checks
@smoke
Scenario: Verify active checks are displayed on Initial Loading of the application
Given User Opens the Station Check Application
When The Transmission Date is within six months
Then Verify the list of station checks displayed in the page
最佳答案
我从这个帖子中得到了答案: https://stackoverflow.com/a/50349499/10468882
粘合必须是包名称而不是路径。
关于java - 运行 JUnit 后跳过 Cucumber 步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56958227/