Open henryaboutshen opened 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
)?
What regarding other steps? Will they never use regex (ex.
When(I do [a])
will matchI do [a]
orI 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?
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.
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?
@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();
})
Describe the bug Brackets in the step will make it not to locate step definitions.
To Reproduce Steps to reproduce the behavior:
Expected behavior The step will be associated with code in step definitions.
Screenshots
Cucumberautocomplete part of VSCode settings:
Step definition:
Gherkin step line