Testing / Cucumber Interview Questions
How do you troubleshoot an "Undefined step" error in Cucumber?
An "undefined step" error means Cucumber couldn't find any step definition whose pattern matches a given Gherkin line's text, and it's one of the most common early friction points when writing or modifying feature files.
- Check the glue configuration - confirm the runner's
cucumber.gluesetting actually points at the package containing the relevant step definitions; a correct step definition in the wrong (unscanned) package produces exactly this error. - Check for typos or subtle wording differences - Cucumber Expressions and regex both require an exact structural match; a step definition written for
{string}won't match text using unquoted values, and small wording differences between the feature file and the pattern are a frequent cause. - Check parameter type mismatches - a step definition expecting
{int}won't match a step passing a non-numeric value in that position. - Use Cucumber's snippet suggestion - when a step is genuinely undefined, Cucumber prints a ready-to-use step definition skeleton matching that exact text in its output, which is often the fastest way to confirm exactly what pattern is expected.
- Check for accidentally duplicated or conflicting glue paths - a misconfigured multi-module project can end up scanning the wrong glue package, or none at all, depending on how paths are set up.
Most undefined-step errors trace back to either a glue configuration issue (the code exists but isn't being scanned) or a genuine mismatch between the feature file's exact wording and the step definition's pattern, rather than a deeper problem with Cucumber itself.
More Related questions...