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

"The gherkin step has 0 arguments" while there is one argument #515

Closed
tomaszwojciechowski opened this issue Oct 26, 2018 · 7 comments
Closed

Comments

@tomaszwojciechowski
Copy link

In .feature I've: When I wait for 2 seconds,
Cucumber expression: @And("I wait for (\\d+) seconds").
For test execution I get: "the gherkin step has 0 arguments".

@mlvandijk
Copy link
Member

mlvandijk commented Oct 26, 2018

It looks to me like you are mixing cucumber expressions and regex. Could you please try replacing (\d+) with {int}?

@tomaszwojciechowski
Copy link
Author

@mlvandijk Thank you- {int} works. At the same I think that (\d+) should also work, acording to https://docs.cucumber.io/cucumber/cucumber-expressions/ ("You can use Regular Expressions or Cucumber Expressions.").

@mlvandijk
Copy link
Member

@tomaszwojciechowski Yes, but in that case you need to start your String with ^ and end with $, like this: @And("^I wait for (\\d+) seconds$").

@tomaszwojciechowski
Copy link
Author

@mlvandijk Thank you.

@aslakhellesoy
Copy link
Contributor

We're using some simple using heuristics in ExpressionFactory.java to determine if an expression string should be interpreted as a CucumberExpression or a RegularExpression.

It sounds like these heuristics could be improved. I'd be very grateful if you submitted a pull request to improve this @tomaszwojciechowski! It's a nice, small problem to work on.

aslakhellesoy added a commit that referenced this issue Oct 30, 2018
mpkorstanje added a commit that referenced this issue Mar 16, 2019
Explaining when a string is interpreted as a cucumber expression should
be rather straight forward. In essence the explanation should be:

    If you surround a string with `^` and `$` it will be a regular
    expression. If not, it is a cucumber expression.

However the heuristic complicates this by checking if a capture group
contains regular expression symbols `[]+.*` with the assumption that
these are not used in normal writing.

This allows us to write little marvels like:

    this looks\( i.e: no regex symbols) like a cukexp
    a heavy storm forecast \(BF {int}+)
    the temperature is (\+){int} degrees celsius

Which look deceptively like cucumber expressions but are in fact regular
expressions. Simplifying the heuristic remove this ambiguity. This does
comes at the cost of being able to recognize obvious regular
expressions.

    this (.+) like a regexp
    this (\d+) like a regexp
    this ([a-z]+) like a regexp

But I think the simplicity is worth it.

Related:
  * cucumber/cucumber-jvm#1581
  * #515
aslakhellesoy added a commit that referenced this issue Jul 1, 2019
@ghost
Copy link

ghost commented Sep 2, 2019

It looks to me like you are mixing cucumber expressions and regex. Could you please try replacing (\d+) with {int}?

Isn't it possible to mix regular expressions and cucumber expressions?

@luke-hill
Copy link
Contributor

It is not no. You need to use one or the other. Because the characters mean different things in the different constructs. I.e. () are optional characters in cuke exp, but they are capturing groups in regexp

aslakhellesoy pushed a commit to cucumber/cucumber-expressions that referenced this issue Sep 20, 2021
Explaining when a string is interpreted as a cucumber expression should
be rather straight forward. In essence the explanation should be:

    If you surround a string with `^` and `$` it will be a regular
    expression. If not, it is a cucumber expression.

However the heuristic complicates this by checking if a capture group
contains regular expression symbols `[]+.*` with the assumption that
these are not used in normal writing.

This allows us to write little marvels like:

    this looks\( i.e: no regex symbols) like a cukexp
    a heavy storm forecast \(BF {int}+)
    the temperature is (\+){int} degrees celsius

Which look deceptively like cucumber expressions but are in fact regular
expressions. Simplifying the heuristic remove this ambiguity. This does
comes at the cost of being able to recognize obvious regular
expressions.

    this (.+) like a regexp
    this (\d+) like a regexp
    this ([a-z]+) like a regexp

But I think the simplicity is worth it.

Related:
  * cucumber/cucumber-jvm#1581
  * cucumber/common#515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants