[Cucumber] Run Feature File with Tags
Katalon Studio supports executing a single feature file with the runFeatureFileWithTags function, using the following tag expressions:
| Expression | Description |
|---|---|
@tag1 and @tag2 | Features or scenarios tagged with both @tag1 and @tag2. |
@tag1 or @tag2 | Features or scenarios tagged with either @tag1 or @tag2. |
To learn more about tag expressions, refer to this Cucumber document: Cucumber tag expression.
Description​
Execute the features or scenarios associated with all or any the input tags.
Keyword name: runFeatureFileWithTags
Keyword syntax: runFeatureFileWithTags(relativeFilePath, tags, cucumberRunOptions, flowControl)
Parameters​
| Parameter | Parameter Type | Required | Description |
|---|---|---|---|
| relativeFilePath | String | Yes | The relative path to the feature file that starts from the current project location. To rerun failed scenarios, provide the path to your rerun file prefixed with @ (e.g., @rerun.txt). |
| tags | String, String[], or String... (Varargs) | Yes | The tags of the features or scenarios that you want to execute. |
| cucumberRunOptions | Map | No | A map of options to configure the Cucumber execution. Use failedTestFilePath to specify a file path where failed scenarios will be saved. |
flowControl (only valid when tags are of String[] type) | FailureHandling | Optional | Controls the execution flow if the step fails. Specify failure handling schema to determine whether the execution should be allowed to continue or stop. |
Returns​
An instance of CucumberRunnerResult that includes the status of the keyword and report folder location.
Examples​
Example 1: Using tags of String type
// With AND expression
CucumberKW.runFeatureFileWithTags("Include/features/New Feature File.feature", "@tag1 and @tag2")
// With OR expression
CucumberKW.runFeatureFileWithTags("Include/features/New Feature File.feature", "@tag1 or @tag2")
Example 2: Using tag arrays (String[])
// With AND expression
String[] logTags = ["@tag1 and @tag2"] as String[]
CucumberKW.runFeatureFileWithTags("Include/features/New Feature File.feature", logTags, FailureHandling.STOP_ON_FAILURE)
// With OR expression
String[] logTags = ["@tag1 or @tag2"] as String[]
CucumberKW.runFeatureFileWithTags("Include/features/New Feature File.feature", logTags, FailureHandling.STOP_ON_FAILURE)
Example 3: Using Varargs (String...)
CucumberKW.runFeatureFileWithTags("Include/features/New Feature File.feature", "@tag1 and @tag2")
Example 4: Capture and rerun failed scenarios
// Run tests and generate rerun file with failed scenarios
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'])