How to create dynamic glue in cucumber java based on the feature file location?

googytech picture googytech · Apr 7, 2016 · Viewed 15.7k times · Source

I am having a java project which is built using maven.

I have multiple packages,feature files based on different functionalities. The project test structure is as below.

src
  ->test
    ->java
      ->com
        ->usercreation
          TestStepDef.java
        ->uservalidation
          TestStepDef.java
   ->resources
        ->usercreation
           usercreation.feature
        ->uservaliation
           uservalidatin.feature

I have only one RunCukesTest.java file

@RunWith(Cucumber.class)
@CucumberOptions(format = { "html:target/cucumber-html-report",
                        "json:target/cucumber-json-report.json" }, 
                        features = "src/test/resources/",
                        glue = "??????",
                        tags = {"~@ignore"}
            )
 public class RunCukesTest {

 }

In this case it runs all my feature files. But it is not able to find my specific Step definitions for the feature. So I have to give the glue option as "com.usercreation". But if I do so when it runs the uservalidation feature file it will not be able to pick up the appropriate step definition. In my use case I don't want both the step def file to be in the same package, as they have many steps with different functionalities.

Is there a possible way where I can give the glue option dynamically based on the package name the feature file is running. Or am I missing any other approach to this project.

Answer

MikeJRamsey56 picture MikeJRamsey56 · Apr 8, 2016
glue = { "classpath:com/usercreation", "classpath:com/uservalidation" },