Skip to content

How to Retry a complete Failed Scenario in CodeceptJS with Playwright and BDD (Gherkin)? #5003

Open

Description

@Nikitha22735

I'm using CodeceptJS with the Playwright helper and BDD-style Gherkin syntax for writing tests. I want to retry an entire scenario if it fails, rather than retrying individual steps.

For example, if a scenario fails due to a temporary glitch (e.g., network issue or slow response), I want the whole scenario to automatically re-run a specified number of times before being marked as failed.

I've found options like retryFailedStep in CodeceptJS config, but that seems to apply only to individual steps.

Is there a built-in way or a recommended approach to retry failed scenarios in CodeceptJS when using Gherkin?

I'd appreciate any examples or configuration snippets if available.

Activity

  1. apatelia commented on Jul 11, 2025

    @apatelia

    Did you try Scenario().retry() ?

    https://codecept.io/basics/#retry-scenario

  2. Ntripur commented on Jul 21, 2025

    @Ntripur

    However, since I'm using BDD-style tests with Gherkin syntax, I can't use Scenario().retry() directly — it's only available in code-based scenarios, not in .feature files. I have hundreds of Gherkin scenarios, so manually converting them to programmatic definitions just to add retries isn't practical.

    Is there a way to apply retries globally or configure retries for Gherkin scenarios, possibly through hooks or the configuration file?

  3. myrepojuly commented on Jul 21, 2025

    @myrepojuly

    Hi @Nikitha22735 @Ntripur

    Just use this

    Before((test)=>{
           // you can use test.tags to filter the feature/scenarios
    
    test.retries(1)
    })
    

    like wise at the suite level as well.

    Additionally, to set re-tries in the config, refer retry

  4. Ntripur commented on Jul 21, 2025

    @Ntripur

    thanks for the reply @myrepojuly
    I think the code below doesn't work in BDD/Gherkin-style tests:
    Before((test)=>{
    // you can use test.tags to filter the feature/scenarios

    test.retries(1)
    })

  5. myrepojuly commented on Jul 21, 2025

    @myrepojuly

    @Ntripur I am using BDD/Gherkin and it works with both the above methods.

    Not sure how you are using the hooks and the configs…

  6. myrepojuly commented on Aug 23, 2025

    @myrepojuly

    Kindly share a reproducible code to review.

  7. github-actions commented on Nov 22, 2025

    @github-actions

    This issue is stale because it has been open for 90 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions