vny uppara
vny uppara

Reputation: 119

Cucumber - Undefined Steps Though defined

I'm creating a Simple Selenium Cucumber project and defined steps using "Lambda Expressions Constructor" way for a feature file but when I ran the CucumberTest class I'm getting failure exception as

There are undefined steps!

My StepDefinition is below one

enter image description here And Feature file is the below one

enter image description here

CucumberRunner class is below:

enter image description here

So please suggest me is there any different approach for calling Step Definition File if I use Lambda Expressions?

Upvotes: 0

Views: 1587

Answers (1)

SubOptimal
SubOptimal

Reputation: 22973

As already mentioned in my comment. The option glue expects a list of package names, not directories. Changing it from

glue = {"src/test/java/my.project.automation.wolfram_alpha" }

to

glue = {"my.project.automation.wolfram_alpha" }

will solve the issue.

Find working snippets below. Assuming following structure

src/test/java/my/project/automation/wolfram_alpha/StepDef.java
src/test/java/my/project/automation/wolfram_alpha/cucumberTest.java
src/test/resources/wolfram.feature
pom.xml

pom.xml (dependencies part)

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <version.cucumber>3.0.2</version.cucumber>
</properties>
<dependencies>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java8</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

cucumberTest.java

package my.project.automation.wolfram_alpha;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

@CucumberOptions(
        features = { "src/test/resources/wolfram.feature" },
        glue = {"my.project.automation.wolfram_alpha" }
)
public class cucumberTest extends AbstractTestNGCucumberTests {
}

StepDef.java

package my.project.automation.wolfram_alpha;

import cucumber.api.java8.En;

public class StepDef implements En {
    public StepDef() {
        Given("URL of WolframAlpha" , () -> {
            System.out.println("Given URL of WolframAlpha");
        });
        When("user logged in as {string} with {string}" , (String user, String password) -> {
            System.out.printf("When user logged in as {%s} with {%s}%n", user, password);
        });
        And("login is successful" , () -> {
            System.out.println("And login is successful");
        });
        And("user search for a {string}" , (String topic) -> {
            System.out.printf("And user search for a {%s}%n", topic);
        });
        Then("results are displayed in a creative way" , () -> {
            System.out.println("Then results are displayed in a creative way");
        });
    }
}

wolfram.feature from the question

Running the test with mvn test produces following output.

Running my.project.automation.wolfram_alpha.cucumberTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@726f3b58
Given URL of WolframAlpha
When user logged in as {user} with {password}
And login is successful
And user search for a {IDOL}
Then results are displayed in a creative way

1 Scenarios (1 passed)
5 Steps (5 passed)

Upvotes: 1

Related Questions