Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step containing regex capture group not found #323

Closed
ckorakidis opened this issue Sep 12, 2022 · 3 comments
Closed

Step containing regex capture group not found #323

ckorakidis opened this issue Sep 12, 2022 · 3 comments

Comments

@ckorakidis
Copy link

ckorakidis commented Sep 12, 2022

👓 What did you see?

step: And a message is sent with a mobile
glue: Then("a message is sent (with|without) a mobile") { withOrWithout: String =>
error message: io.cucumber.junit.UndefinedStepException: The step 'a message is sent with a mobile' is undefined.

✅ What did you expect to see?

Step should be picked and "with" or "without" should be the captured value

📦 Which tool/library version are you using?

Cucumber Scala 8.9.0
Cucumber core 7.7.0

🔬 How could we reproduce it?

Scenario: Regex capture
    Given wte
    And a message is sent with a mobile

and

Then("a message is sent (with|without) a mobile") { withOrWithout: String =>
  assert(withOrWithout == "with"
}

the error:

2022-09-12 09:56:22.644  [error] Test SomeFeature - SomeFeature failed: io.cucumber.junit.UndefinedStepException: The step 'a message is sent with a mobile' is undefined.
2022-09-12 09:56:22.644  [error] You can implement this step using the snippet(s) below:
2022-09-12 09:56:22.644  [error] 
2022-09-12 09:56:22.644  [error] Then("""a message is sent with a mobile""") { () =>
2022-09-12 09:56:22.644  [error]   // Write code here that turns the phrase above into concrete actions
2022-09-12 09:56:22.644  [error]   throw new io.cucumber.scala.PendingException()
2022-09-12 09:56:22.644  [error] }
2022-09-12 09:56:22.644  [error] , took 8.307 sec
@ckorakidis
Copy link
Author

Looks like I missed start and end in the glue, the following works:

Then("^a message is sent (with|without) a mobile$") { withOrWithout: String =>
  assert(withOrWithout == "with"
}

@gaeljw
Copy link
Member

gaeljw commented Sep 12, 2022

Indeed, in Cucumber terminology, without start and end, the string is interpreted as a "Cucumber Expression" whereas with it it's interpreted as a regular regex.

Cucumber Expression can still be used for your use case but by defining a custom type like (not tested, there might be typos):

ParameterType("withOrWithout", "(with|without)") { (str) =>
  str
}

Then("a message is sent {withOrWithout} a mobile") { withOrWithout: String =>
}

See https://github.com/cucumber/cucumber-expressions#readme

@ckorakidis
Copy link
Author

Good to know, thanks @gaeljw !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants