Create Test Cases Using BDD Feature File

Behavior-Driven Development (BDD) is a software development approach that uses natural language to define expected behavior. It helps ensure the software works as intended and improves collaboration through a shared understanding of requirements.

Import test cases from .feature files following Gherkin syntax from:

  • From the Requirement module (BDD section)

  • Test Case module

  • While creating or updating a test case

Permissions Required

The following table lists the permissions required for each operation:

Operation

Required Permissions

Import Test Case

Import, Test Case View, Create, Edit and Archive

Update Test Case

Test Case View, Edit and Archive

Link Test Case

Test Case View, Edit and Archive

Link Requirement

Test Case View, Requirement View and Edit

Add Labels

Configuration View and Modify

Parameter

Configuration View (reuse), Modify (create)

File Requirements

  • Supported file:

    • Format: .feature files

    • Size: 10 MB

    • Import Limit: 1 file or a ZIP file with up to 10 .feature files.

Note

Mapping Feature File with Fields for Import

The following table lists the mapping of the feature file with fields:

Scenario

Mapping

Example/Note

Scenario Name

Test Case Summary

It can be a Scenario, Scenario Outline, or Example.

Feature Name

Test Case Description

-

Scenario Steps

Test Steps

Includes Keyword and Step

Supported Gherkin Keywords
  • Given

  • When

  • Then

  • And

  • But

  • * (asterisk)

Data Table in Steps

Steps Summary

| username | password |

| validUser | invalidPass |

| invalidUser | validPass |

| validUser | validPass |

Docstrings in Steps

Part of Step Description in Steps

"""

{

"username": "validUser", "password": "validPass"

}

"""

Tags

Labels

Tags are added as labels.

@testcasekey

Test Case Key

If the specified key exists in , the system creates a new version of the test case with updates from the feature file.

Define multiple test case keys for a single scenario.

QPro_TC_BDD_File.png

@requirementkey

Requirements

  • If the specified requirement key exists in QMetry, the test case is linked to it.

  • At the scenario level, all test cases in the scenario are linked.

  • At the feature level, all test cases in the feature file are linked.

  • If the key is invalid, not found, or access is denied, the test case is created without linkage.

  • Cross-project requirement keys are supported.

    QPro_TC_CrossProject_QKey_in_BDD_File.png

Background Steps (Scenario Level)

Steps

Gets added as initial steps of the test case.

Background Step (Feature File Level)

Steps - before all the scenario steps

i.e Initial Steps of all Test Cases

Gets added as initial steps for all test cases created from the Feature file.

Rule

Description

Appends to Description along with feature name separated by semicolon

Examples (Scenario Outline)

Parameters

The values listed in the Examples table becomes @Parameters in the test steps and variables becomes Parameters.

Parameter and Value Handling
  • If a parameter exists in a project accessible to you, the system reuses it.

  • If the parameter value does not exist, the system auto-creates it.

  • If a parameter exists but you do not have access to the associated project, the system creates a new parameter with the project key appended to its name.

  • Data Grid Generation

    • The system creates a Data Grid named in the format: DataGrid_<Test Case Key>.

    • The system associates the data grid with the same project as the test case.

    • The system adds all relevant parameters and values from the Scenario Outline to the data grid.

  • Updating Existing Data Grid

    • If a data grid already exists for a test case, QMetry updates it whenever the test case is modified or versioned.

    • Any new parameters or values introduced during the update are added to the existing data grid.

Sample Files

Sr. No.

File Content

Download Sample File

1

Feature File with multiple scenarios

2

Feature File with Scenario Outline

3

Feature file with Scenario and Scenario Outlines

4

Feature file with Rule, Rule Example Cases

5

Feature file with Rule, Scenario Cases & Background

6

Example for Data Parameters under Table Data

Import Options

During import, the system processes test cases and labels based on the import option selection:

QPro_TC_BDD_Import_Options.png

Test Case Key Handling

If a Test Case Key is specified:

  • Update Current Version

    • Updates the existing version of the test case.

    • Applicable only to test cases that are unarchived, not executed, and not approved.

  • Create New Version

    • Adds a new version to the existing test case.

    • Applicable only to unarchived test cases.

Label Handling

If the specified labels are not found in the project:

  • Create: Adds labels to Configuration and applies them to the test case.

  • Ignore: Skips missing labels.

Note

  • Import fails for archived, approved, or executed test case keys.

  • To create new “Labels” you need “Modify Label” permissions.

Import and Create Test Cases From a BDD Feature File

Option1: From the Requirement Module (BDD Section)

You can create test cases from a feature file or Gherkin syntax in the BDD section of the Requirement module.

QPro_TC_Import_FeatureFile_From_RQ_BDD_.png

Note

Configure the BDD section under BDD Configuration tab in Project Settings.

To create test cases from BDD section in requirement module, perform the following steps:

  1. Open the Requirement details page.

  2. Go to the BDD section.

  3. Sync the feature file with the Source Control repository.

  4. Select the feature files associated with the requirement to create test cases.

  5. Fill system and custom fields.

  6. Select import options for Test Case Keys and Labels.

  7. Click Create.

Track import progress in Scheduled Tasks.

Note

  • All imported test cases inherits the selected field values.

  • Preferences are saved for future imports.

Option 2: From Test Case Module

Create BDD test cases by importing a feature file directly from the Test Case module.

Note

Importing feature file from Test Case module does not require BDD Configuration.

QPro_TC_Import_Feature_File_from_TC.png

To import test cases from a feature file, perform the following steps:

  1. Go to the Test Case module.

  2. Click the Cog icon and select Import from Feature File.

  3. Upload a file.

  4. Fill in the required details.

  5. Select Import Options for Test Case Key handling and labels.

  6. Click Create.

Monitor the import status in Background Jobs section.

Once the import is complete, expand the entry to view test case details. In case of a failure, expand to view the error details.

Option 3: Using BDD Syntax

You can directly create or update test cases by pasting the Gherkin syntax from a feature file.

Updating an Existing Test Case

You can reuse a test case by updating it with new Gherkin syntax from a feature file.

Updating_an_Existing_Test_Case__1_.png

To update an existing test case from a feature file, perform the following steps:

  1. Open an existing test case.

  2. Click Scenario.

    QPro_TC_BDDScenario.png
  3. Paste the BDD content.

  4. Select the operation:

    • Update Current Version

    • Create New Version

  5. Create New Version keeps the current version and creates a new one with updated details.

  6. Update Current Version overrides and replaces the existing Summary, Description, and Steps with the new details from the feature file.

Creating a New Test Case

Create a new test case scenario from feature file.

To create a new test case from a feature file, perform the following steps:

  1. Click New and select Scenario.

  2. Enter a scenario from a feature file and click Import.

  3. Fill in all mandatory fields and enter the test case details.

  4. Click Create.

A new test case is created in the specified folder. If no folder is specified, the test case is created in the root folder.

Note

  • When creating or updating a test case using a Scenario or Scenario Outline:

    • The Scenario name is used as the Test Case Summary.

    • The Steps are mapped to Test Steps.

    • Any Data Tables or Doc Strings within steps are added to the Step Description.

    • Only the fields listed above are supported.

    • Tags, Test Case Keys, and Requirement Keys are not supported in this method.

Known Limitations

When importing test cases from BDD .feature files authored in Cucumber, please note the following limitations:

  • Gherkin Keywords Are Not Displayed

    • The system does not display step keywords such as Given, When, Then, And, *, in the imported test steps.

  • Data Tables and Doc Strings Not Captured

    • The system does not support import of data tables and doc strings used within steps into the step description.

  • Background Steps Not Imported

    • Background steps defined in the feature file are currently not imported into the test case.

    • You need to add these common setup steps manually, if required.

Note

Review and manually adjust the imported steps if these elements are critical to their test scenarios.

Publication date: