Cucumber Test 步骤未在 J-Unit 中显示,而在控制台步骤已成功运行

Wes*_*sCo 1 java junit cucumber

我目前正在尝试创建我的第一个 Cucumber 测试。在 Java Eclipse 中,我创建了一个包含以下内容的“功能文件”:

Feature: Login functionality DemoQA.com

Scenario: Verify if user is able to login to the DemoQA website
    Given A user is on DemoQA.com
    When User clicks MyAccount link
    Then User is taken to Login Page
    When User enters valid username and password
    Then User is able to login 
Run Code Online (Sandbox Code Playgroud)

我还创建了以下 testrunner 文件:

@RunWith(Cucumber.class)
@CucumberOptions(   
        features = "src/test/Features/",
        glue = {"Tests"}
        )
public class CucumberRunner {
}
Run Code Online (Sandbox Code Playgroud)

我还创建了我的 Stepdefinitions:

公共类 LoginStepDefinitions {

@Given("A user is on DemoQA.com")
public void a_user_is_on_DemoQA_com() {

     System.setProperty("webdriver.gecko.driver","C:\\geckodriver-v0.10.0-win64\\geckodriver.exe");

         WebDriver driver = new FirefoxDriver();
         WebDriverWait wait = new WebDriverWait(driver, 50);

         String url = "https://demoqa.com";

            //Launch the Online Store Website
            driver.get(url);

try {

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"logo-events\"]/a/img")));   
            driver.findElement(By.xpath("//*[@id=\"logo-events\"]/a/img"));
            System.out.println("User has succesfully opened DemoQA.com");

             } 

catch (Exception e) {
            System.out.println("User was not able to open DemoQA.com");

            }

}

@When("User clicks MyAccount link")
public void user_clicks_MyAccount_link() {
    // Write code here that turns the phrase above into concrete actions
    System.out.println("User clicks on the MyAccount link");
}

@Then("User is taken to Login Page")
public void user_is_taken_to_Login_Page() {
    System.out.println("User is succesfully taken to MyAccount login");
}

@When("User enters valid username and password")
public void user_enters_valid_username_and_password() {
    System.out.println("User enters valid credentials for MyAccount login");
}

@Then("User is able to login")
public void user_is_able_to_login() {
    // Write code here that turns the phrase above into concrete actions
    System.out.println("User is succesfully logged in");
}
Run Code Online (Sandbox Code Playgroud)

}

当我将脚本作为 Junit 测试运行时,控制台成功执行测试并显示结果:

User has succesfully opened DemoQA.com
[32m.[0mUser clicks on the MyAccount link
[32m.[0mUser is succesfully taken to MyAccount login
[32m.[0mUser enters valid credentials for MyAccount login
[32m.[0mUser is succesfully logged in
[32m.[0m
1 Scenarios ([32m1 passed[0m)
5 Steps ([32m5 passed[0m)
0m7.706s
Run Code Online (Sandbox Code Playgroud)

但是当打开 JUnit 选项卡时会发生两件事:

1)似乎没有显示测试步骤:

在此处输入图片说明

2) 当我双击功能/场景步骤时,我收到一条消息:

在所选项目中未找到测试类

阅读了有关此主题的其他一些帖子后,我的第一个想法是我的功能文件未位于正确的文件夹中,但我现在几乎将其移动到了任何地方,而且似乎没有任何区别。

这是我在 Eclipse 中的当前结构:

在此处输入图片说明

有人可以帮我吗?谢谢!

小智 5

@CucumberOptions 中的答案 'junit = "--step-notifications"' 对我不起作用。但幸运的是,我立即找到了解决方案。

@CucumberOptions
(
    features="path to feature file",

    glue="path to step definition file",

    stepNotifications = true
)

Run Code Online (Sandbox Code Playgroud)