If you are starting fresh with end-to-end (E2E) testing in .NET against a live online website, Reqnroll + Playwright is a practical, modern starting point. Reqnroll lets you write readable Gherkin scenarios and bind them to C#, while Playwright automates real browsers with built-in auto-waiting and async/await support.

In this starter tutorial, we will walk through a brief history of C# browser testing, set up a minimal project, run a scenario against a live page (using the W3Schools HTML Forms page as an example), and cover locators and trade-offs.

A Short History of E2E Testing in C Sharp

  • 2006 – 2010 — WatiN and Early Browser Automation: Early .NET browser automation started with tools like WatiN, driving Internet Explorer via COM on Windows. It proved automated UI testing worked, though cross-browser and modern web app support were limited.
  • 2010 – 2020 — SpecFlow + Selenium WebDriver: SpecFlow brought Gherkin BDD to .NET and paired with Selenium WebDriver to become the enterprise standard for years. Teams liked human-readable scenarios, though suites often dealt with manual waits, external driver binaries, and HTTP command overhead.
  • 2020 – 2023 — Playwright for .NET: Playwright arrived with first-class async/await support in C#, automatic actionability checks, isolated browser contexts, and built-in tracing—solving many timing and debugging headaches of older browser drivers.
  • 2024 – Present — SpecFlow End-of-Life and Reqnroll: SpecFlow reached end-of-life at the end of December 2024, and its original creator launched Reqnroll as the active open-source successor for .NET—keeping Gherkin and step-binding concepts familiar while supporting modern .NET versions.

Project Structure

Keep your starter project small and easy to follow:

LiveE2ETests/ ├── Features/ │ └── OnlineForm.feature # Plain-English Gherkin scenario ├── Hooks/ │ └── BrowserHooks.cs # Starts and stops Playwright per scenario ├── StepDefinitions/ │ └── OnlineFormSteps.cs # C# steps bound to Gherkin └── LiveE2ETests.csproj 

Step-by-Step Setup

1. Create the Reqnroll Project and Install Playwright

Requires the .NET 8 SDK (or newer). Open a terminal and scaffold a new NUnit-based Reqnroll test project:

dotnet new install Reqnroll.Templates.DotNet mkdir LiveE2ETests && cd LiveE2ETests dotnet new reqnroll-project -t nunit 

Next, install Microsoft.Playwright, build the project once, and download the Chromium browser binary:

dotnet add package Microsoft.Playwright dotnet build pwsh bin/Debug/net8.0/playwright.ps1 install chromium 

2. Write a Gherkin Scenario for a Live Page

Remove the default sample files in Features/ and StepDefinitions/, then create Features/OnlineForm.feature:

Feature: Live Website Form As a visitor I want to open a live form page and interact with its inputs So that I verify the live site renders and accepts input properly Scenario: Fill the name fields on the live W3Schools form page Given I open "https://www.w3schools.com/html/html_forms.asp" When I enter first name "Grace" and last name "Hopper" Then the first name field should have value "Grace" And the last name field should have value "Hopper" 

3. Add Browser Lifecycle Hooks

Create Hooks/BrowserHooks.cs to launch a fresh browser context per scenario, register IPage in Reqnroll's dependency container (IObjectContainer), and close the browser after each scenario completes:

using Microsoft.Playwright; using Reqnroll; using Reqnroll.BoDi; namespace LiveE2ETests.Hooks; [Binding] public class BrowserHooks { private readonly IObjectContainer _container; private IPlaywright? _playwright; private IBrowser? _browser; public BrowserHooks(IObjectContainer container) { _container = container; } [BeforeScenario] public async Task BeforeScenario() { _playwright = await Playwright.CreateAsync(); _browser = await _playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = true // Set to false to watch the browser run }); var context = await _browser.NewContextAsync(); var page = await context.NewPageAsync(); _container.RegisterInstanceAs(page); } [AfterScenario] public async Task AfterScenario() { if (_browser is not null) await _browser.CloseAsync(); _playwright?.Dispose(); } } 

4. Implement Step Definitions in C

Create StepDefinitions/OnlineFormSteps.cs. Notice that we use a realistic navigation timeout for live internet traffic, check for an optional consent button, and assert using Playwright's web-first Expect(...) API:

using Microsoft.Playwright; using Reqnroll; using static Microsoft.Playwright.Assertions; namespace LiveE2ETests.StepDefinitions; [Binding] public class OnlineFormSteps { private readonly IPage _page; public OnlineFormSteps(IPage page) { _page = page; } [Given("I open {string}")] public async Task GivenIOpen(string url) { await _page.GotoAsync(url, new PageGotoOptions { WaitUntil = WaitUntilState.DOMContentLoaded, Timeout = 30_000 }); // Optional: dismiss a consent button if the live site displays one var acceptButton = _page.GetByRole(AriaRole.Button, new() { Name = "Accept all" }); if (await acceptButton.IsVisibleAsync()) { await acceptButton.ClickAsync(); } } [When("I enter first name {string} and last name {string}")] public async Task WhenIEnterFirstAndLastName(string firstName, string lastName) { await _page.Locator("#fname").FillAsync(firstName); await _page.Locator("#lname").FillAsync(lastName); } [Then("the first name field should have value {string}")] public async Task ThenTheFirstNameFieldShouldHaveValue(string expectedValue) { await Expect(_page.Locator("#fname")).ToHaveValueAsync(expectedValue); } [Then("the last name field should have value {string}")] public async Task ThenTheLastNameFieldShouldHaveValue(string expectedValue) { await Expect(_page.Locator("#lname")).ToHaveValueAsync(expectedValue); } } 

5. Run the Test

Run the suite from your terminal or IDE Test Explorer:

dotnet test 

Playwright launches Chromium, loads the live URL, fills in the fields, and verifies the values.

Finding HTML Elements (Do You Need XPath?)

Usually, no. Prefer user-facing locators (GetByRole, GetByLabel, GetByText) or clean CSS selectors (#fname, [name='lname'])—they are easier to read and less brittle when markup shifts. Reach for XPath only when you need something CSS cannot express, such as walking up from a child element to a parent container.

Quick workflow to pick locators:

  1. Inspect the element in browser DevTools (F12) and look for accessible labels, roles, data-testid, or clean IDs rather than copying deep div > div > span chains.
  2. Run with $env:PWDEBUG="1"; dotnet test (PowerShell) or PWDEBUG=1 dotnet test (Unix) to open Playwright Inspector and test locators interactively.

Pros, Cons, and Live-Site Caveats

Pros Cons
Readable Specs: Plain-English Gherkin helps align devs, QA, and stakeholders. Extra Abstraction Layer: Maintaining .feature files and step bindings adds overhead for small codebases.
Auto-Waiting: Playwright waits for elements to become actionable before interacting. Step Sprawl: Needs clean naming and page helpers as your suite grows.
Built-In Diagnostics: Screenshots, videos, and trace logs simplify debugging. Slower Than Unit Tests: Browser tests take longer to run than unit or service tests.

A few extra things to keep in mind on live websites:

  • Iframes & popups: If a target input sits inside an <iframe>, use _page.FrameLocator("...").Locator("...").
  • External flakiness & ethics: Live sites can have consent modals, network slowdowns, rate limits, or layout changes—keep test data harmless and avoid hammering public sites.
  • Selenium in the past: SpecFlow + Selenium WebDriver was the classic .NET stack for years. Selenium still makes sense if you maintain an existing suite or rely on a Selenium Grid setup, while Playwright is often smoother for new projects today.