DEV Community

Emmanuel Salazar
Emmanuel Salazar

Posted on

Tutorial: Selenium WebDriver + Reqnroll

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.

  1. Open Visual Studio 2022.
    From the start window, choose "Continue without code."
    Visual Studio Main<br>
Page

  2. Open the Extensions Manager.
    Navigate to Extensions → Manage Extensions.
    Options in the top menu<br>
bar

  3. Search for "Reqnroll for Visual Studio 2022."
    Extension<br>
description

  4. 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**.
Enter fullscreen mode Exit fullscreen mode

💡 Tip: Reqnroll is the open-source successor to SpecFlow --- fully
compatible with .NET 8 and Visual Studio 2022.


🧩 Step 2 --- Create a Reqnroll Project

  1. Open the "Create a New Project" window.
    From the start screen, click Create a new project.

  2. Search for "Reqnroll Project."
    Select it from the list and click Next.
    Create a new Project with Reqnroll<br>
Project

  3. Configure project details.
    Enter a Project name, choose a Location, and set the Solution name.
    Click Create.
    Project<br>
name

  4. Select your testing framework.
    Choose MSTest as the Test Framework, then click Create.
    Framework and Test<br>
Framework

  5. Verify the template.
    By default, a sample project called Calculator is generated to demonstrate structure.
    Calculator


🧩 Step 3 --- Add Selenium Dependencies

To interact with browsers, you need to install Selenium via NuGet
Packages
.

  1. Go to Tools → NuGet Package Manager → Manage NuGet Packages for Solution...
    NuGet<br>
Packages

  2. Under the Browse tab, search and install:

-   `Selenium.WebDriver`
-   `Selenium.WebDriver.ChromeDriver`
Enter fullscreen mode Exit fullscreen mode

💡 Tip: Ensure the ChromeDriver version matches your installed
version of Google Chrome.


🧩 Step 4 --- Create a Feature File and Step Definitions

  1. Open the Solution Explorer and locate the Features folder.
    Features<br>
Folder

  2. Add a new Feature File.
    Right-click Features → Add → New Item.

  3. Choose the template.
    Select Reqnroll → Feature File for Reqnroll, then click Add.
    Reqnroll<br>
Items

  4. Name the file (e.g., Search.feature) and click Add.
    You'll now have an empty .feature file with Gherkin structure.
    Search<br>
BDD

  5. 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"
Enter fullscreen mode Exit fullscreen mode
  1. Build the project.
    The Gherkin text will turn purple, indicating that steps are
    recognized but not yet implemented.
    Purple<br>
Gherkin

  2. Generate the step definitions.
    Right-click any Gherkin line → Define Steps...Create.
    Step Definitions<br>
Creation
    Steps Definitions<br>
File


🧩 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();
Enter fullscreen mode Exit fullscreen mode

🧠 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/");
}
Enter fullscreen mode Exit fullscreen mode

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();
}
Enter fullscreen mode Exit fullscreen mode

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));
}
Enter fullscreen mode Exit fullscreen mode

✅ If the searched word appears among results, the test passes.
❌ Otherwise, the assertion fails.


5️⃣ Run the Test

  1. Open View → Test Explorer.
  2. Run the test from there.
  3. 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.

Test Explorer Result


✅ 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)