Diagnosing Cucumber Glue Errors: A Step‑by‑Step Guide to Fix Missing Step Definitions
When Cucumber reports ‘Undefined steps’ or ‘Could not find glue’, the culprit is often a mis‑configured step definition package. This guide walks through the most common glue errors, how to identify them, and how to resolve them in Cucumber‑JVM 7/8 projects.
24 Aug 2026, 12:28 UTC

Recognizable Condition
During a test run you see messages such as:
Feature: User login
Scenario: Successful login
Given I open the login page
When I enter valid credentials
Then I should see the dashboard
Undefined steps:
3 undefined steps found in 1 scenario (3.00s)
1) Given I open the login page
2) When I enter valid credentials
3) Then I should see the dashboard
All steps are marked as undefined and no step definitions are executed.
Common Causes
| Symptom | Probable Cause |
|---|---|
| All steps undefined | Glue package not scanned or step definitions not compiled |
| ‘Could not find glue’ error | Runner’s glue attribute points to wrong package or missing |
| ‘No matching step definitions’ | Step annotations use wrong Gherkin keyword or regex mismatch |
| Feature file fails to parse | Malformed Gherkin (indentation, tabs, non‑ASCII quotes) |
| Build fails before test runner starts | Missing or incompatible cucumber‑java / cucumber‑junit dependencies |
Diagnostic Checklist
- Verify Maven/Gradle dependencies – ensure
cucumber-javaandcucumber-junitare present and the same major version.mvn dependency:tree | grep cucumber # or gradle dependencies | grep cucumber - Check test runner class – confirm it uses
@RunWith(Cucumber.class)and the@CucumberOptions(glue = "com.myapp.steps")attribute.@RunWith(Cucumber.class) @CucumberOptions( features = "src/test/resources/features", glue = {"com.myapp.steps"}, plugin = {"pretty"} ) public class RunCucumberTest {} - Confirm step definition package – the package name in
gluemust match the package where step classes reside. On case‑sensitive OS,com.myapp.stepsis different fromcom.MyApp.steps.package com.myapp.steps; public class LoginSteps { ... } - Validate step annotations – each method should be annotated with
@Given,@When, or@Thenand the expression must match the Gherkin step.@Given("I open the login page") public void openLoginPage() { ... } - Inspect Gherkin syntax – ensure
Scenarioheaders are correctly indented, tabs are avoided, and quotes are plain ASCII.Scenario: Successful login Given I open the login page When I enter valid credentials Then I should see the dashboard - Run tests with pretty plugin –
mvn test -Dtest=RunCucumberTest -Dplugin=prettyorgradle test --tests RunCucumberTest --infoto see detailed output.- Look for lines like
Undefined steps:orCould not find glue.
- Look for lines like
- Check IDE integration – enable Cucumber plugin’s “Show Gherkin Outline” to cross‑check that each feature step is linked to a step definition.
Step‑by‑Step Fixes
1. Glue Package Mismatch
Update @CucumberOptions(glue = ...) to point to the correct package or add the missing package to the scan. If you have multiple packages, list them all:
@CucumberOptions(glue = {"com.myapp.steps", "com.myapp.moresteps"})
After change, clean and rebuild the project.
2. Missing or Incorrect @RunWith Annotation
Ensure the test runner extends Cucumber. In JUnit 4:
@RunWith(Cucumber.class)
public class RunCucumberTest {}
For JUnit 5 with Cucumber 8+, use @Cucumber from io.cucumber.junit.platform.engine.Cucumber and a @CucumberOptions annotation.
3. Step Annotation or Regex Mismatch
Verify that the regex in the annotation matches the Gherkin step text. Common pitfall: using a dash or special character in the step that isn’t escaped in the regex.
@When("I enter valid credentials")
public void enterCredentials() { ... }
Use .* or named groups only when necessary.
4. Gherkin File Encoding or Syntax
Open the feature file in a UTF‑8 editor without BOM. Replace tabs with spaces (two spaces per level). Verify that all quotes are straight double quotes (U+0022). If the file contains non‑ASCII characters, escape them or use unicode escape sequences.
5. Dependency Version Mismatch
Cucumber‑JVM 7.x and 8.x share the same package layout, but 9.x introduces a new cucumber-java8 module. Ensure all cucumber dependencies are the same major version. In Maven:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>8.15.0</version>
</dependency>
6. IDE Plugin Mis‑configuration
Some IDEs cache step definitions. In IntelliJ, invalidate caches: File → Invalidate Caches / Restart. In VS Code, reload the window.
Escalation Criteria
- If after the fixes the console still shows
Undefined steps, runmvn dependency:treeto confirm no conflicting cucumber artifacts. - Check the classpath by printing
System.getProperty("java.class.path")inside the test runner to ensure step classes are present. - If the runner cannot locate the glue, try adding
classpath:/to theglueattribute. - When using a build tool plugin (e.g., Gradle Cucumber plugin), verify that the plugin is applied and that it uses the same cucumber version.
- If the issue persists, create a minimal reproducible example: a single feature file, one step definition, and a runner. If the minimal example works, the problem lies in project configuration or other tests.
Limitations
This guide covers the most common glue errors in Cucumber‑JVM 7/8. It does not address:
- Runtime errors inside step definitions (e.g., NullPointerException).
- Feature files that use
BackgroundorScenario Outlinewith data tables that cause parsing errors. - Cross‑project step reuse via
@CucumberOptions(glue = "classpath:/…")in complex multi‑module setups.
Always validate the test output after each change. A clean run with no undefined steps confirms the issue is resolved.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.