We have a Spring Boot app and we want to start from within this app the execution of a Cucumber feature.
Whenever the user clicks a button in the spring app, then the call comes in a class (CucumberTestService
) where we start the execution of our Cucumber feature.
Here is the structure of the source code that is interesting for us:
- src
-main
-com
-bino
-panel
-server
-reference
-cucumber
-steps
-SendMessagesDefs.java
-CucumberTestService.java
We prepare the arguments in CucumberTestService
:
String[] args = new String[]{
"--strict",
"--glue",
"com.bino.panel.server.reference.cucumber.steps",
"--plugin",
"pretty",
"/CUCUMBER-FEATS/" + feature + ".feature",
"--plugin",
"json:" + reports_path + "/cucumber-reports-" + feature + "/Cucumber.json",
"--plugin",
"junit:" + reports_path + "/cucumber-reports-" + feature + "/Cucumber.xml",
"--plugin",
"html:" + reports_path + "/cucumber-reports-" + feature,
"--plugin",
"usage:" + reports_path + "/cucumber-reports-" + feature + "/cucumber-usage.json",
"--plugin",
"pretty:" + reports_path + "/cucumber-reports-" + feature + "/cucumber-pretty.txt"
};
then we are trying to launch it in the following way - exactly as it is launched in cucumber.api.cli.Main
:
run(args, Thread.currentThread().getContextClassLoader());
Now this works pretty fine in our IDE (Eclipse & IntelliJ), however when we pack this in a spring boot jar it stops working.
For deployment, the whole application is bundled up in one jar and has the following structure :
- BOOT-INF
-classes
-com
-bino
-panel
-server
-reference
-cucumber
-steps
-lib
- META-INF
MANIFEST.ML
- org
-springframework
-boot
-loader
When trying to execute it, Cucumber does not seem to be able to find the implementation that is defined in the glue parameter:
1 Scenarios (1 undefined)
7 Steps (7 undefined)
0m0.000s
We spent quite some time to investigate this issue and came down to the conclusion that the Cucumber is not able to find
the classes from this path "com.bino.panel.server.reference.cucumber.steps"
when executing it from a Spring Boot jar.
But they are found correctly when the same code is execute from an IDE (Eclipse, IntelliJ).
Any suggestion of how can we "help" Cucumber & Spring find the glue classes within a spring boot jar?
Jar Versions used (taken from our build.gradle
file):
- compile group: 'io.cucumber', name: 'gherkin', version: '6.0.14'
- compile(group: 'info.cukes', name: 'cucumber-java8', version: '1.2.5')
- compile(group: 'io.cucumber', name: 'cucumber-junit', version: '4.2.6')
- compile(group: 'io.cucumber', name: 'cucumber-picocontainer', version: '2.4.0')
Spring Boot version is 2.1.3
Any help/suggestion/ideas are highly appreciated! Many thanks!