0

If I have a feature that looks like this:

Feature: My feature
  Scenario Outline: My scenario outline.
    Given foo
    When bar
    Then I get the status code "<Status Code>".

  Examples:
   | StatusCode |
   |        200 |

and a step definition like this:

@Then("I get the status code {int}.")

Cucumber complains and says that the step is undefined, because it's expecting the type to be {string}. Is there a way to specify the type in the feature or the example table? I've looked into the TypeRegistryConfiguration but I can't work out how to make it work with feature files.

7
  • 1
    Use <Status Code> not "<Status Code>". Commented Apr 30, 2024 at 14:50
  • 1
    Or \"{int}\" if the quotes are important. Commented Apr 30, 2024 at 14:51
  • @M.P.Korstanje that was it, thank you! I didn't realise that adding the quotes would cast it to a string. If you'd like to add this as an answer I'll accept it. Commented Apr 30, 2024 at 15:11
  • It doesn't. What doess your step definition look like? Commented Apr 30, 2024 at 15:40
  • public void i_get_the_status_code(Integer expectedStatusCode). If I put the quotes back, it stops working with the same error, so they do seem to be the problem. Commented Apr 30, 2024 at 16:15

2 Answers 2

1

Is there a typo in the feature file? There seems to be a problem with the quotation marks.

Then I get the status code "<Status Code">

Furthermore, I hope you are using 'Scenario Outline' instead of just 'Scenario'. If we pass in values as arguments, we should be using Scenario Outline.

Edit1: Thanks for that, @M.P. Korstanje. Didn't know about that feature.

Another thing that might be the issue is this. Step Definition Mismatch - Ensure that your step definition method signature exactly matches the step in your feature file. Hope this fixes it as I can't think of anything else.

Sign up to request clarification or add additional context in comments.

2 Comments

FYI: Scenario Outline and Scenario are synonyms now. If you are on a recent version of Cucumber.
Good catch, I didn't see that typo. I've fixed it in the question and expanded on the example.
0

Removing the quotes around <StatusCode> as suggested by @M.P.Korstanje fixed it. After doing that, Cucumber then recognised it as an integer and picked up the step defintion.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.