'Cucumber Test steps not showing in J-Unit while in console steps have run successfully

I'm currently trying to create my first Cucumber tests. In Java Eclipse I have created a 'Feature file' with the following content:

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 

I also created the following testrunner file:

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

I also created my Stepdefinitions:

public class 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");
}

}

When I run my script as a Junit test, the console succesfully executes the test and shows the result:

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

But when opening the JUnit tab two things happen:

1) Teststeps don't seem to be shown:

enter image description here

2) When I doubleclick the Feature / Scenario steps I get a message:

Test Class not found in selected project

Having read some of the other posts around this subject, my first thought was that my feature file was not located in the correct folder, but I have moved it almost everywhere now and it does not seem to make any difference.

This is my current structure in Eclipse:

enter image description here

Can anybody help me out please? Thx!



Solution 1:[1]

The answer 'junit = "--step-notifications"' in @CucumberOptions did not work for me. But fortunately, i found the solution immediately.

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

    glue="path to step definition file",

    stepNotifications = true
)

Solution 2:[2]

'junit = "--step-notifications"' in @CucumberOptions did not work for me as well.

I did this:

@CucumberOptions(
stepNotifications = true,
strict = true,
features="path to feature file",
glue="path to step definition file")

and its working. My teststeps also appeared in the Junit result.

strict = true -- is for suppressing the Waring :

This default will change to --strict and --non-strict will be removed. You can use --strict or @CucumberOptions(strict = true) to suppress this warning

Solution 3:[3]

Add the below code in TestRunner and you will see the step notifications enabled.

@CucumberOptions(features="src/test/java/features", glue={"stepDefinitions"}, stepNotifications=true)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sugat Shivsharan
Solution 2 Mona Chalpe
Solution 3 Elikill58