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

Unable to create step definition with | operator with latest version #299

Closed
fayizkc opened this issue Jun 24, 2024 · 1 comment
Closed

Comments

@fayizkc
Copy link

fayizkc commented Jun 24, 2024

👓 What did you see?

When I try to create step as below

Then Verify "user" exist in the list
Then Verify "user" not exist in the list

with single step definition, it is not identifying. I have create stepDef as below

@Then ("Verify {string} (|not) exist in the list")
public void verifyUserExist(String username, String exist){
   if(exist.isEmpty){
     //check exist
 }
}

showing error as "Step undefined
You can implement this step using the snippet(s) below:"

✅ What did you expect to see?

This was working with older cucumber version I hope when i check in this Issue

📦 Which tool/library version are you using?

Cucumber version: 7.15.0

🔬 How could we reproduce it?

No response

📚 Any additional context?

No response

@fayizkc fayizkc changed the title Unable to create a step definition with | operator with latest version Unable to create step definition with | operator with latest version Jun 24, 2024
@mpkorstanje
Copy link
Contributor

Capturing an optional element of expression is not possible with a Cucumber expressions. It looks like you may have been mixing regular and Cucumber Expressions. This should not have been possible and was fixed with cucumber/common#771.

To match your step with regular expressions you would either have to use a regular expression

  • ^Verify "([^"]*)" (|not )exist in the list$

Note: the extra space after not.

Or with Cucumber Expressions, you would use two separate step definitions.

  • Verify {string} not exist in the list
  • Verify {string} exist in the list

The latter is probably better. While it does result in more lines of code, it keeps each step one focused on its own distinct task. If not you can probably factor out a more generic helper method. Or use the regular expressions.

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

No branches or pull requests

2 participants