Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 958
googytech Avatar asked Dec 14 '22 07:12

googytech


1 Answers

glue = { "classpath:com/usercreation", "classpath:com/uservalidation" },
like image 179
MikeJRamsey56 Avatar answered Jan 11 '23 23:01

MikeJRamsey56