alexkrechik / VSCucumberAutoComplete

Cucumber (Gherkin) Full Support Extension for VSCode
https://marketplace.visualstudio.com/items?itemName=alexkrechik.cucumberautocomplete
MIT License
331 stars 80 forks source link

Unable to find step def. for step containing parentheses #405

Closed emily25inGoFreight closed 4 months ago

emily25inGoFreight commented 3 years ago

Describe the bug Unable to find step def. for step containing parentheses, e.g., When the user click 'Gross Weight (SHPR)' for box(2). For situation like parentheses in braces, it's fine. But when there are only parentheses, then it won't work. Whether there are quotes does not affect the result.

To Reproduce Steps to reproduce the behavior:

  1. Go to a feature file
  2. Right click on the step in editor, and click 'Go to Definition'
  3. See error

Expected behavior Expected to find the step definition.

Cucumberautocomplete part of VSCode settings:

{
    "cucumberautocomplete.steps": [
        "features/steps/*.py"
    ],
    "cucumberautocomplete.syncfeatures": "features/*.feature",
    "cucumberautocomplete.strictGherkinCompletion": true,
    "cucumberautocomplete.skipDocStringsFormat": true
}

Step definition: If applicable, add example of step definition:

@When("the user click 'Gross Weight (SHPR)' for box({box_index})")
def step_impl(context, box_index):
    pass

Gherkin step line If applicable, add step line from gherkin file When the user click 'Gross Weight (SHPR)' for box(2)

koichirok commented 3 years ago

Parentheses are used for optional text in cucumber expressions, and must be escaped in order for the parentheses to be matched literally.

So example step definition above should be:

@When("the user click 'Gross Weight \(SHPR)' for box\({box_index})")
def step_impl(context, box_index):
    pass

However, even if the step definition is correct, the result is still the same. Cannot jump to the step definition with 'Go to Definition'.

As a workaround, I use regular expressions for step definitions in such cases.

ahmdgawad commented 3 years ago

I have similar issue in Java: @When("a file named {string} is created") Was unable to find step for "When a file named 'abc' is created.

@koichirok Can you please mention how you used regex in step definitions?

emily25inGoFreight commented 3 years ago

I have similar issue in Java: @When("a file named {string} is created") Was unable to find step for "When a file named 'abc' is created.

@koichirok Can you please mention how you used regex in step definitions?

In this case, maybe you should add single quote around {string}, like @When("a file named '{string}' is created")

emily25inGoFreight commented 3 years ago

Parentheses are used for optional text in cucumber expressions, and must be escaped in order for the parentheses to be matched literally.

So example step definition above should be:

@When("the user click 'Gross Weight \(SHPR)' for box\({box_index})")
def step_impl(context, box_index):
    pass

However, even if the step definition is correct, the result is still the same. Cannot jump to the step definition with 'Go to Definition'.

As a workaround, I use regular expressions for step definitions in such cases.

Since changing all test case to regular expressions may require lots of effort, my current approach is add this in settings

"cucumberautocomplete.customParameters": [
        {
            "parameter":"(SHPR)",
            "value":"\\(SHPR\\)"
        }
    ]

But I'm still hoping that there could be an update for this.

ahmdgawad commented 3 years ago

Parentheses are used for optional text in cucumber expressions, and must be escaped in order for the parentheses to be matched literally. So example step definition above should be:

@When("the user click 'Gross Weight \(SHPR)' for box\({box_index})")
def step_impl(context, box_index):
    pass

However, even if the step definition is correct, the result is still the same. Cannot jump to the step definition with 'Go to Definition'. As a workaround, I use regular expressions for step definitions in such cases.

Since changing all test case to regular expressions may require lots of effort, my current approach is add this in settings

"cucumberautocomplete.customParameters": [
        {
            "parameter":"(SHPR)",
            "value":"\\(SHPR\\)"
        }
    ]

But I'm still hoping that there could be an update for this.

Thanks, it worked that way, However I made a long list as the plugin was catching braces in javadoc also. And its nearly impossible to change all test cases (1000+). Hope to get a fix for this.

alexkrechik commented 2 years ago

Like the same with https://github.com/alexkrechik/VSCucumberAutoComplete/issues/222

alexkrechik commented 2 years ago

Should be fixed with "cucumberautocomplete.pureTextSteps": true option using after 2.16.0 release.

alexkrechik commented 4 months ago

This issue is to be fixed or implemented in the 3.0.0 version of the extension. If this issue is unresolved or there are additional notes, please create a new ticket with the necessary details.