运行JUnit后跳过的黄瓜步骤

时间:2019-07-09 17:57:05

标签: java selenium junit cucumber

我正在使用Cucumber Selenium启动我的测试自动化项目。我使用JUnit运行了testrunner -它通过了Feature和Scenario行,但是跳过了步骤(给出,何时,然后)。我在每个步骤上都添加了打印行命令,以查看它是否将运行这些步骤。有人可以帮我解决这个问题吗?

这是我的StepDefinition:

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();
}

这是我的TestRunner

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

1 个答案:

答案 0 :(得分:2)

我从这个线程得到了答案: https://stackoverflow.com/a/50349499/10468882

胶水必须是包装名称,而不是路径。

相关问题