javajunitcucumber

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

  • I have solved the issue myself by adding the following line in the @cucumberoptions of my Runner file: junit = "--step-notifications" . After adding this line in the runner file, my testssteps also appear in the Junit result. Question can be closed