vitalets / playwright-bdd

BDD testing with Playwright runner
https://vitalets.github.io/playwright-bdd/
MIT License
302 stars 36 forks source link

Question: Cucumber AutoComplete issue for steps with multiple variants. #230

Open gitToSantosh opened 2 days ago

gitToSantosh commented 2 days ago

Problem When I have steps like below:

Then I see link with text "How to install Playwright" should be displayed
Then I see link with text "How to install Playwright" should not be displayed

and step as below

Then( 'I see link with text {string} should( not) be displayed', async ( { page, $step }, text: string ) => {
    const negate = /should not/.test( $step.title );
    if ( negate ) {
        await expect( page.getByRole( 'link', { name: text } ) ).toBeHidden();
    } else {
        await expect( page.getByRole( 'link', { name: text } ) ).toBeVisible();
    }
} );

Cucumber autocomplete only identifies the negation step and fails to identify the positive step and shows as warning

Alternatively, when i use below step

Then( 'I see link with text {string} should(| not) be displayed', async ( { page, $step }, text: string ) => {
    const negate = /should not/.test( $step.title );
    if ( negate ) {
        await expect( page.getByRole( 'link', { name: text } ) ).toBeHidden();
    } else {
        await expect( page.getByRole( 'link', { name: text } ) ).toBeVisible();
    }
} );

Cucumber autocomplete identifies both positive and negative steps, but here bddgen fails to identify one of the steps

Please provide some solutions

vitalets commented 2 days ago

It's a bug in CucumberAutocomplete: https://github.com/alexkrechik/VSCucumberAutoComplete/issues/292 I've tried with official Cucumber extension, it handles optional part correctly and navigates to the definition from both steps. So for now I suggest to switch on it if applicable.

Also I've submitted a fix to https://github.com/alexkrechik/VSCucumberAutoComplete/pull/509. Lets keep this issue open to track the progress.