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

Brackets in the step will make it not to locate step definitions #415

Open henryaboutshen opened 2 years ago

henryaboutshen commented 2 years ago

Describe the bug Brackets in the step will make it not to locate step definitions.

To Reproduce Steps to reproduce the behavior:

  1. Define a step in step_definitions with brackets.
  2. Write code in feature file.

Expected behavior The step will be associated with code in step definitions.

Screenshots overflow feature

Cucumberautocomplete part of VSCode settings:

{
    "cucumberautocomplete.steps": [
        "src/*/cypress/support/step_definitions/*.js"
    ],
    "cucumberautocomplete.syncfeatures": "src/*/cypress/integration/*.feature",
    "cucumberautocomplete.smartSnippets": true,
    "cucumberautocomplete.stepsInvariants": true
}

Step definition:

When('[Table] I click the table header', () => {
    cy.get('table th').click();
})

Gherkin step line

Scenario: Click table header
    When [Table] I click the table header
alexkrechik commented 2 years ago

What regarding other steps? Will they never use regex (ex. When(I do [a]) will match I do [a] or I do a)?

henryaboutshen commented 2 years ago

What regarding other steps? Will they never use regex (ex. When(I do [a]) will match I do [a] or I do a)?

Step with regex looks like:

Gherkin

Scenario: header
    When I open overflow page
    Then I see element ".header"

Step definition

Then('I see element {string}', (elem) => {
    cy.get(elem).should('be.visible');
});

I tried the example you mentioned above and it worked in VS Code but failed in the cypress execution. So does it mean that I cannot use brackets in the cypress step definition?

alexkrechik commented 2 years ago

First of all, tests should pass in the cypress execution. After this, 99.9% that extension setup will help to write steps for the executor.

henryaboutshen commented 2 years ago

First of all, tests should pass in the cypress execution. After this, 99.9% that extension setup will help to write steps for the executor.

Thanks for your reply. I think I know where the problem is. So how to modify settings file to make brackets are recognized as characters instead of regex in the step?

rioj7 commented 2 years ago

@henryaboutshen Using

Then('I see element {string}' is not using a regex, it uses a string that is converted to a regex by substituting the {xxxx} fields with a regex part that matches that field type.

If you want to have [] in the step description in the feature file, use a regex in the step definition with some characters excaped

When(/\[Table\] I click the table header/, () => {
    cy.get('table th').click();
})

I think you can even add fields to a regex:

When(/\[Table\] I click the table {string}/, () => {
    cy.get('table th').click();
})