Cucumber/Java - Missing "matching glue code" - java

I've setup some automation in Eclipse using Java, Cucumber and Selenium.
I've defined my Feature file, Steps and been using a Page Object Model and all my tests are running and reporting successfully.
However, I'm getting a warning on every Step saying it "does not have matching glue code". I've tried modifying my path names and moving the files around, but that just seems to cause issues that prevent it running.
Using cucumber 6.2.2 jars and cucumber-expressions 10.2.1
Folder Structure
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src/test/resources/functionalTests"},
tags = "#register2",
glue = {"stepDefinitions"},
plugin = {"pretty", "html:target/cucumber-reports.html"},
monochrome = true
)

In your glue option can you write full package name.
For example:
com.testautomation.test.stepdefinitions

Related

Java Maven Cucumber how to correctly rerun tests from the commandline?

Hi i'm using i'm currently using Cucumber version 6.8.1 and i'm trying to figure out how to solve rerunning of failed tests. I've hacked together my own solution but it feels incorrect. In order for
maven clean install
to detect the test runners i appended Test to their names:
#RunWith(Cucumber.class)
#CucumberOptions(plugin = { "de.monochromata.cucumber.report.PrettyReports:target/cucumber", "rerun:target/rerun.txt" })
public class CucumberRunnerTest {
}
and
#RunWith(Cucumber.class)
#CucumberOptions(
features = "#target/rerun.txt",
plugin = {"pretty", "html:target/site/cucumber-pretty",
"json:target/cucumber.json"}
)
public class RerunningTest {
}
Now this works but it seems a bit hacky. since commands like
mvn clean install -Dcucumber.glue="cucumber" \
-Dcucumber.plugin="de.monochromata.cucumber.report.PrettyReports:target/cucumber" \
-Dcucumber.plugin="rerun:target/rerun.txt"
should work, but don't work. The build is successful but no tests run. It's like Dcucumber is being ignored by maven. However, after appending "Test" to the runners and then running the command above uses both runners since they're treated as Tests which feels wrong.
So my question is how can i make this work correctly with Dcucumber?
If you don't name your test class *Test then Surefire won't recognize it. Naming convention wise, try using RunCucumberTest instead. It isn't too ugly.
https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
Inclusions and Exclusions of Tests
Inclusions
By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
If the test classes do not follow any of these naming conventions, then configure Surefire Plugin and specify the tests you want to include.

Create step definitions with underscore in IntelliJ

I was going through this post IntelliJ - Cucumber step definition case
But I don't see cucumber config in IntelliJ community edition version 11.0.8.
I already have Cucumber Java plugin installed.
Restarted IntelliJ after adding --snippets underscore but it is still giving camelcase.
So how can I get underscore instead of camelcase?
To get underscore instead of camel case add the below properties in your junit-platform.properties . If this file does not exist , you can create and place it in src/test/resources . Junit5 will detect it automatically and run based on configs provided in that file. For junit5 , we should be using this in pom cucumber-junit-platform-engine
cucumber.plugin = summary
cucumber.snippet-type=underscore
cucumber.execution.dry-run= true
For a scenario like this in feature file
Given I log this <TestTest>
When you build project in intellij , cucumber will generate this on console. You can copy this in stepdefs
#Given("I log this {string}")
public void i_log_this(String string) {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
If you are using junit 4 you have to use corresponding options in your
#RunWith(Cucumber.class)
You can find related information on this cucumber docs

Parameterise JUnit CucumberOptions through Jenkins

I am busy with a BDD automation project that is coded in Java. We use Cucumber to run the BDD. The JUnit class that we use to kick off the run is as follows:
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"usage", "json:target/cucumber.json", "html:target/cucumber", "com.cucumber.listener.ExtentCucumberFormatter:"},
glue = {"BDD.step_definitions"},
features = {"Unit-Tests\\Features"},
dryRun = false,
monochrome = false,
strict = true
)
The issue that I am having is that I would like to parameterize the CucumberOptions through Jenkins, ideally setting the feature file or scenario name through a Jenkins choice parameter.
I am using AntBuild to build and test my project on Jenkins. Would it be possible to set the CucumberOptions on the build XML?
You are interested in understanding how you can send arguments to the Java process you run in Jenkins.
Setting Cucumber options can be done like this:
-Dcucumber.options="--help"
If you are running from Maven, it would look like this:
mvn test -Dcucumber.options="--help"
Running a specific tag could be done like this:
-Dcucumber.options="--tags #wip"
More details can be found in the Cucumber docs or in a blog post I wrote a while back.

how to specify cucumber tags as invocation param in eclipse debug configuration?

I have a Spring Boot project. In it I have a java class BookTests which contains:
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {
"pretty",
"html:target/acceptance-test-report",
"json:target/cucumber/cucumber.json"
},
glue = {
"com.my.sdk.test",
"com.my.book.test"
}
,tags = {"#findConsideringGrants"}
)
public class BookTests {
// No implementation required. The Cucumber annotations drive the test execution.
}
I'm using Junit 4. when I "Debug As JUnit Test" this class it only runs the feature file which is annotated with "#findConsideringGrants (as it should)
Is there a way i don't have to hard-code this tags annotation in the java class but instead specify the tags as Program argumnents or VM arguuments?
I tried configuring it with Program argumnents, but with all the following attempts it ignored the argument and ran the tests on all my features/tags:
--tags findConsideringGrants
-tags findConsideringGrants
--tags #findConsideringGrants
-tags #findConsideringGrants
So to summerize, i'm looking for a way to
1) debug in eclipse a certain feature
2) without hardcoding the name of the feature into the java source. Somehow by just configuring the debug configuration.
is this even possible?
If you are using maven you can use -- mvn test -Dcucumber.options="--tags #findConsideringGrants".
Or you can use the cucumber cli command to run -- Main.main(new String[]{"-g", "classpath to step definition file","-t", "tags to use", "-p", "plugins to use", "Full path to feature file"}). The feature file path has to be the last option.
Running from eclipse --
Go to the "Environment" tab of the "Debug Configurations" or "Run Configurations" window. Click on "New" button. For the "Name" add "cucumber.options" and "Value" add "--tags #findConsideringGrants". Apply and Run. If you want to add a specific feature file path add only the path to the end of this.

Cucumber JVM undefined step

I can't execute a simple test with cucumber for a project. I am on Intellij 13 Community, with cucumber plugin.
I wrote my feature file in my features directory, I have also implemented my steps, creating them with the help of the plugin. And my steps in the feature files are recognized by intellij, which can navigate and go to the step implementation.
But when I try to run my scenario, it always fails because for each step, it says "Undefined step : ".
Here is how is organized my project :
And as I said before, you can see that my steps are recognized by Intellij :
How is that possible, and how can I correct this?
Any help would be great!
EDIT
Now that I added options to my runner :
#CucumberOptions( monochrome = true,
features = "src/test/resources/features/",
format = { "pretty","html: cucumber-html-reports",
"json: cucumber-html-reports/cucumber.json" },
dryRun = false,
glue = "fr.tlasnier.cucumber" )
It works!
Yet, I noticed that before that, I had two scenario outline. One worked perfectly, the other one could not find step definition!
Really weird, since there were some steps in both scenario.
#RunWith(Cucumber.class)
#CucumberOptions( monochrome = true,
tags = "#tags",
features = "src/test/resources/features/",
format = { "pretty","html: cucumber-html-reports",
"json: cucumber-html-reports/cucumber.json" },
dryRun = false,
glue = "fr.tlasnier.cucumber" )
public class RunCucumber_Test {
//Run this
}
In my case, i was running with intellij cucumber for java plugin, it doesnt automatically detect the glue, so you need to add it.
Run -> Edit Configurations
Then on the Glue section, put the steps folder path.
The class in which the steps are defined should be public. Anything else would throw the undefined step error.
I've met the same problem. And found that if the package where step definitions exists has not been created in the corresponding source folder.
You can try to create a class under fr.tlasnier.cucumber.step, then idea should be able to find the steps. I think it is a bug in Idea.

Categories