【问题标题】:Skipped Cucumber steps after running JUnit运行 JUnit 后跳过 Cucumber 步骤
【发布时间】:2019-11-19 08:16:06
【问题描述】:

我正在使用 Cucumber Selenium 开始我的测试自动化项目。我使用 JUnit 运行了我的测试运行程序——它通过了 Feature 和 Scenario 行,但跳过了这些步骤(Given、When、Then)。我在每个步骤上都放了打印行命令,只是为了看看它是否会运行这些步骤。有人可以帮我解决这个问题吗?

这是我的 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

【问题讨论】:

  • 注释掉“抛出新的 PendingException();”陈述,并将功能文件添加到此问题中。谢谢
  • 结果没有变化。我已经附上了上面的功能文件。
  • junit 正在从 ide、命令行、maven pom 运行......
  • 我使用 Eclipse 运行它。我现在得到了答案。我在另一条评论中发布了它的来源。

标签: java selenium junit cucumber


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多