CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

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

Open Nikitha22735 opened this issue 7 months ago • 7 comments

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.

Nikitha22735 avatar May 30 '25 15:05 Nikitha22735

Did you try Scenario().retry() ?

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

apatelia avatar Jul 11 '25 11:07 apatelia

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?

Ntripur avatar Jul 21 '25 14:07 Ntripur

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

myrepojuly avatar Jul 21 '25 14:07 myrepojuly

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) })

Ntripur avatar Jul 21 '25 15:07 Ntripur

@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…

myrepojuly avatar Jul 21 '25 15:07 myrepojuly

Kindly share a reproducible code to review.

myrepojuly avatar Aug 23 '25 18:08 myrepojuly

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

github-actions[bot] avatar Nov 22 '25 02:11 github-actions[bot]