This article is part of the “Introduction to E2E Testing with Reqnroll × Playwright” series.
- Reqnroll Feature File Tutorial: BDD Syntax (Given When Then)
- What You’ll Learn in This Guide
- What Is a Feature File?
- Basic Structure of a Feature File
- BDD Keywords Explained
- Example: Login Scenario
- How to Write Each Section
- Using Parameters in Feature Files
- Best Practices for Writing Feature Files
- How Reqnroll Executes Feature Files
- Summary
Reqnroll Feature File Tutorial: BDD Syntax (Given When Then)
Conclusion
Reqnroll Feature files let you write test scenarios in plain, human-readable language using BDD.
By using Given / When / Then, you can create tests that are easy to understand, maintain, and share across teams.
What You’ll Learn in This Guide
In this tutorial, you’ll learn:
- What a Feature file is
- How Given / When / Then work
- Basic Gherkin syntax in Reqnroll
- Real examples of Feature files
- Best practices for writing clean scenarios
This guide is perfect for developers getting started with BDD in .NET using Reqnroll.
What Is a Feature File?
A Feature file is a text file where you describe test scenarios in a readable format.
File Extension
.feature
Example
Login.feature
Feature files use Gherkin syntax, which allows you to describe behavior like a specification.
Basic Structure of a Feature File
A typical Feature file looks like this:
Feature: Login
Scenario: Successful login
Given I open the login page
When I enter valid credentials
Then I should see the dashboard
This structure describes user actions and expected results.
BDD Keywords Explained
Feature files rely on a small set of keywords:
| Keyword | Meaning |
|---|---|
| Feature | The functionality being tested |
| Scenario | A single test case |
| Given | Preconditions |
| When | User actions |
| Then | Expected results |
| And | Additional steps |
These keywords form the foundation of BDD-style testing.
Example: Login Scenario
Here’s a more complete example:
Feature: Login
Scenario: Login with valid credentials
Given I open the login page
When I enter email "test@example.com"
And I enter password "password123"
And I click the login button
Then I should see the dashboard
What This Scenario Does
- Opens the login page
- Enters email and password
- Clicks the login button
- Verifies the dashboard is displayed
This mirrors real user behavior in a clear and readable way.
How to Write Each Section
Feature
The Feature describes what functionality you are testing.
Feature: Login
You can also add a description:
Feature: User Login
Verify that users can log into the application
Scenario
A Scenario represents a single test case.
Scenario: Login with valid credentials
You can define multiple scenarios under one feature:
- Successful login
- Invalid password
- Empty input
Given
Given defines the initial state or precondition.
Given I open the login page
When
When describes user actions.
When I enter email "test@example.com"
And I enter password "password123"
Use And to chain multiple actions.
Then
Then defines the expected result.
Then I should see the dashboard
This step verifies that the test passed.
Using Parameters in Feature Files
You can pass dynamic values using parameters:
When I enter email "test@example.com"
These values are passed to Step Definitions.
Example (C# Step Definition)
[When(@"I enter email ""(.*)""")]
public async Task EnterEmail(string email)
{
await _page.Locator("#email").FillAsync(email);
}
This connects your Feature file to executable test code.
Best Practices for Writing Feature Files
Write from the User’s Perspective
Focus on user behavior, not technical details.
- ❌ Click button #login
- ✅ Click the login button
Avoid Implementation Details
Feature files should describe what, not how.
- ❌ Use CSS selector #login
- ✅ Click the login button
Keep Scenarios Short
Each Scenario should have a single purpose.
- One for success
- One for failure
This keeps tests clear and maintainable.
How Reqnroll Executes Feature Files
Reqnroll runs tests using the following flow:
Feature File
↓
Step Definitions (C#)
↓
Test Code (Playwright, etc.)
The steps in your Feature file are matched with C# methods, which execute the actual test logic.
Summary
Reqnroll Feature files are the foundation of BDD testing in .NET.
Key takeaways:
- Feature files use Gherkin syntax
- Core structure: Feature, Scenario, Given, When, Then
- Tests are written in a human-readable format
- Scenarios should be simple and user-focused
- Feature files connect directly to C# test code
By mastering Feature files, you can create clear, maintainable, and scalable BDD test scenarios.
