Complete Step-by-Step Tutorial
This tutorial provides a complete, step-by-step guide to creating an
automated testing framework using Selenium, Gherkin (BDD), and
Reqnroll in Visual Studio 2022.
You'll learn how to set up your environment, configure dependencies, and
write your first executable feature file with readable test
scenarios that bridge the gap between business and technical teams.
🧩 Step 1 --- Verify Reqnroll Installation
Before creating your first automation project, make sure that the
"Reqnroll for Visual Studio 2022" extension is installed.
This extension provides the structure and templates required to build a
Behavior-Driven Development (BDD) framework using Gherkin and
Selenium.
Open Visual Studio 2022.
From the start window, choose "Continue without code."
Open the Extensions Manager.
Navigate to Extensions → Manage Extensions.
Check installation status.
- If it shows **Uninstall**, the extension is already installed.
- If not, click **Install**, wait for it to complete, and
**restart Visual Studio**.
💡 Tip: Reqnroll is the open-source successor to SpecFlow --- fully
compatible with .NET 8 and Visual Studio 2022.
🧩 Step 2 --- Create a Reqnroll Project
Open the "Create a New Project" window.
From the start screen, click Create a new project.Search for "Reqnroll Project."
Select it from the list and click Next.
Configure project details.
Enter a Project name, choose a Location, and set the Solution name.
Click Create.
Select your testing framework.
Choose MSTest as the Test Framework, then click Create.
Verify the template.
By default, a sample project called Calculator is generated to demonstrate structure.
🧩 Step 3 --- Add Selenium Dependencies
To interact with browsers, you need to install Selenium via NuGet
Packages.
Go to Tools → NuGet Package Manager → Manage NuGet Packages for Solution...
Under the Browse tab, search and install:
- `Selenium.WebDriver`
- `Selenium.WebDriver.ChromeDriver`
💡 Tip: Ensure the ChromeDriver version matches your installed
version of Google Chrome.
🧩 Step 4 --- Create a Feature File and Step Definitions
Add a new Feature File.
Right-click Features → Add → New Item.Choose the template.
Select Reqnroll → Feature File for Reqnroll, then click Add.
Name the file (e.g.,
Search.feature
) and click Add.
You'll now have an empty.feature
file with Gherkin structure.
Write your first BDD scenario:
Feature: Search
Perform a search on DuckDuckGo to validate that results are displayed correctly.
@smoke @search
Scenario: Search for a keyword in DuckDuckGo
Given the user navigates to the DuckDuckGo homepage
When the user searches for "Reqnroll BDD"
Then the search results should contain the word "Reqnroll"
Build the project.
The Gherkin text will turn purple, indicating that steps are
recognized but not yet implemented.
Generate the step definitions.
Right-click any Gherkin line → Define Steps... → Create.
🧩 Step 5 --- Using Selenium WebDriver with Chrome
The following steps demonstrate a minimal viable automation test
using Reqnroll.
The objective is to show the Given/When/Then flow applied to a simple
web search.
💡 Note:
Best practices like hooks (Before/After) and Page Object Model
(POM) will be covered in later tutorials.
For now, we'll just make it work end to end.
1️⃣ Create the WebDriver
First, we must create our WebDriver in the same class and specify which browser to use.
In this case, we’ll use Google Chrome:
IWebDriver webDriver = new ChromeDriver();
🧠 You don't need to manually download
chromedriver.exe
.
Selenium Manager handles driver setup automatically.
2️⃣ Given Step --- Navigate to the Homepage
The Given step defines the starting context of the test.
Here, we specify which page the browser should open using Navigate().GoToUrl():
[Given("the user navigates to the DuckDuckGo homepage")]
public void GivenTheUserNavigatesToTheDuckDuckGoHomepage()
{
webDriver.Navigate().GoToUrl("https://duckduckgo.com/");
}
3️⃣ When Step --- Perform the Search
In the When step, we define the action that will be performed.
In this example, the user searches for a keyword in the search box:
[When("the user searches for {string}")]
public void WhenTheUserSearchesFor(string p0)
{
var query = webDriver.FindElement(By.Name("q"));
query.Click();
query.SendKeys(p0);
query.Submit();
}
We locate the input by name="q", send the text, and submit the
form.
4️⃣ Then Step --- Validate the Result
The Then step is used to validate the expected outcome.
We look for a search result link that matches our keyword and use an Assert to verify it:
[Then("the search results should contain the word {string}")]
public void ThenTheSearchResultsShouldContainTheWord(string reqnroll)
{
var result = webDriver.FindElement(By.LinkText(reqnroll));
Assert.IsTrue(result.Text.Contains(reqnroll));
}
✅ If the searched word appears among results, the test passes.
❌ Otherwise, the assertion fails.
5️⃣ Run the Test
- Open View → Test Explorer.
- Run the test from there.
- The browser will stay open after execution.
⚠️ That's normal --- we haven't added an After hook to close the
browser yet.
We'll improve that in the next tutorial.
✅ Conclusion
You've just created your first BDD test using Reqnroll and
Selenium!
From here, you can extend it with: - BeforeScenario
/ AfterScenario
hooks
- The Page Object Model (POM) pattern
- Custom assertions and reusable steps
- CI/CD integration with GitHub Actions or Azure Pipelines
Top comments (0)