Jesse Abucejo
Jesse Abucejo

Reputation: 67

Unable to map the step definition glued code

I'm having a problem mapping the glue code from my Feature file to step definition code.

@RunWith(Cucumber.class)
@CucumberOptions(`enter code here`
features = "Features/store.feature"
,glue={"com.test.stepdefinitions/Store.java"}
,monochrome = true
,format={"junit:reports/junit/reports.xml","pretty", "html:reports/html","json:reports/json/Store_reports.json"}

)
public class StoreRunner {

}

When I run this, it will throw this console message:

Feature: Store

Scenario: Delete item from checkout page # Features/store.feature:3

Given the user is in the checkout page # null # null

Upvotes: 0

Views: 1669

Answers (4)

viren tiwari
viren tiwari

Reputation: 21

All you have to do is mentions the Step-definition class name in @CucumberOptions.

Here is the format

@CucumberOptions
{
feature={"path of feature file with extension"},
glue={"Step-definition package Name.class-Name"}
}

Upvotes: 0

Jesse Abucejo
Jesse Abucejo

Reputation: 67

Aprreciate your help guys. I'm able to solve this issue using the latest cucumber version 3.1.0 from io.cucumber and latest selenium jar file from seleniumhq.

Here's my code:

@RunWith(Cucumber.class)
@CucumberOptions(
features = "Features/store.feature"
,glue={"com.bitpoints.stepdefinitions"}
,monochrome = true
,format={"junit:reports/junit/reports.xml","pretty", "html:reports/html","json:reports/json/Login_reports.json"}

)

public class StoreRunner {

}

As you can see I've included "Features/store.feature" in features and it was able to pick the store feature file to be run.

Hope this helps

Running store feature file

Upvotes: 1

Ibtissam
Ibtissam

Reputation: 589

Here is an example of code:

 @RunWith(Cucumber.class)
    @CucumberOptions(features = "src/test/java/features/",  glue = {"steps"}, plugin = {"pretty", "html:target/cucumber", "json:target/cucumber.json"})
    public class RunFeaturesTest {}

project architecture :

enter image description here

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193168

It is not clear from your question if you are using Maven or not but looking at the reports I presume are using Maven.

To map the glue code from the Feature file to Step Definition you need to format the Test Runner class as follows :

  • Mention the directory name containing the FeatureFile instead of providing full path.
  • The value of glue should be set to directory name containing the StepDefinitionClass instead of full path.
  • Move the format attributes within plugin argument.
  • Your Test Runner class file will look like :

    @RunWith(Cucumber.class)
    @CucumberOptions(
        features="Features",
        glue={"stepdefinitions"},
        monochrome = true,
        plugin={"junit:reports/junit/reports.xml"
                "pretty:target/cucumber-pretty.text",
                "html:target/cucumber-html-report",
                "json:target/cucumber.json",
                "usage:target/cucumber-usage.json",
        )
    public class ReportTestRunner 
    {
    }
    

Upvotes: 0

Related Questions