Skip to main content

Rerun failed scenarios

Before version 11.0.0, rerunning failed Cucumber scenarios was a manual process. With this enhancement, you can now automate this by using the cucumberRunOptions parameter to:

  1. Specify a file path to save failed scenarios (failedTestFilePath).
  2. Rerun specific failed scenarios by pointing to that file using the @ syntax.

The following keywords accept the optional cucumberRunOptions parameter:

  • runFeatureFile
  • runFeatureFileWithTags
  • runFeatureFolder
  • runFeatureFolderWithTags

How to use​

cucumberRunOptions is a Map parameter that holds your file path. To use this feature, you need to specify the failedTestFilePath key inside the map.

Example code: The following script captures failed BDD scenarios into a rerun file (rerun.txt) and subsequently executing a targeted retry of only those specific failures.

import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.model.FailureHandling

// Step 1: Run tests and generate rerun file with failed scenarios
CucumberKW.runFeatureFile('Include/features/MyFeature.feature',
[failedTestFilePath: 'rerun.txt'],
FailureHandling.CONTINUE_ON_FAILURE)

// Step 2: Manually rerun only the failed scenarios (if needed)
CucumberKW.runFeatureFile('@rerun.txt',
[failedTestFilePath: 'rerun2.txt'])

// With tags - now with rerun file support
CucumberKW.runFeatureFileWithTags('Include/features/MyFeature.feature',
['@smoke'] as String[],
[failedTestFilePath: 'failed-smoke.txt'],
FailureHandling.CONTINUE_ON_FAILURE)

// Rerun failed smoke tests
CucumberKW.runFeatureFileWithTags('@failed-smoke.txt',
['@smoke'] as String[],
[failedTestFilePath: 'failed-smoke-retry.txt'])
important
  • When rerunning tests, make sure you add the @ prefix to the file path (e.g., @rerun.txt). This informs the engine to treat the file as a list of scenarios rather than a .feature file.
  • The failedTestFilePath is overwritten during every execution. If this key is included in subsequent iterations, the existing file will be replaced regardless of the test run result.
Was this page helpful?