Run Web Automation Tests at Scale with Agentic AI
Generate tests with AI agents or automate test suites with Selenium, Playwright and other frameworks. Run tests in parallel on TestMu AI scalable cloud grid.
Parallel Execution in Reqnroll and SpecFlow with NUnit
Run Reqnroll and SpecFlow scenarios in parallel with NUnit: feature vs scenario scope, thread-safe context injection, and Selenium 4 code for a cloud grid.
Last Updated on:
Parallel execution cuts the wall-clock time of a BDD suite by running scenarios on separate threads, each with its own browser. The .NET framework under those suites has changed: Tricentis retired SpecFlow, and SpecFlow reached end of life on December 31, 2024, with no updates for .NET versions after .NET 7.
Its successor, Reqnroll, lets NUnit run individual scenarios in parallel, while SpecFlow's NUnit integration stopped at whole features. The project below runs five scenarios across Chrome, Firefox and Edge on the TestMu AI cloud grid. To move an existing SpecFlow project first, follow the Reqnroll tutorial.
TL;DR
To run Reqnroll or SpecFlow scenarios in parallel with NUnit, add [assembly: Parallelizable(ParallelScope.Children)] for scenario-level runs or ParallelScope.Fixtures for feature-level runs, cap threads with LevelOfParallelism, and share state only through context injection. Give each scenario its own WebDriver so parallel threads never touch the same browser.
- Scenario-level parallelism: Reqnroll with NUnit runs individual scenarios in parallel through ParallelScope.Children, including scenarios from different features. Reqnroll supports the same scheduling on MSTest and TUnit, while xUnit runs features in parallel only.
- Feature-level parallelism: ParallelScope.Fixtures keeps every scenario of a feature on one thread and runs features side by side. ParallelScope.Fixtures was the only NUnit option SpecFlow offered, and it is the safer choice when steps rely on FeatureContext.
- Thread isolation: Reqnroll runs parallel tests as threads in one process and one application domain, without AppDomain isolation. Static fields are shared across threads, so ScenarioContext.Current throws a ReqnrollException during parallel runs.
- Context injection: A class added as a binding constructor parameter lives for one scenario, and Reqnroll disposes it afterwards when it implements IDisposable. Holding the WebDriver in that class gives every parallel scenario its own browser and a clean quit.
Where Should Parallel Scenarios Run?
A local machine limits parallelism to the browsers it can open at once. On the TestMu AI cloud grid, each scenario opens its own RemoteWebDriver session from LT:Options capabilities, and HyperExecute can split larger suites across parallel virtual machines.
SpecFlow Retirement and the Move to Reqnroll
The specflow.org domain now redirects to a Tricentis page that says "SpecFlow has been retired." Reqnroll's end-of-life notice lists what that means for a running suite:
- SpecFlow - the GitHub projects are deleted and the support section of specflow.org is disabled. Existing NuGet packages still install, but they get no updates for newer .NET, Visual Studio or Rider versions and work only up to .NET 7.
- Reqnroll - an open-source fork of SpecFlow that supports .NET 8 and .NET 9. Bindings, hooks, context injection and the NUnit integration keep the same model, so the parallel setup in this article applies to both.
The code below uses Reqnroll names. In a SpecFlow project, read TechTalk.SpecFlow for Reqnroll, BoDi for Reqnroll.BoDi and SpecFlowException for ReqnrollException.
How Parallel Execution Works in Reqnroll With NUnit
NUnit does not run tests in parallel by default. You switch it on with an assembly-level attribute in the test project, and the attribute's scope decides what runs side by side, as the Reqnroll parallel execution docs describe.
Feature-Level vs Scenario-Level Scope
| Scope | Assembly attribute | What runs side by side | Runners that support it |
|---|---|---|---|
| Feature | [assembly: Parallelizable(ParallelScope.Fixtures)] | Whole features; scenarios from one feature stay on the same thread | NUnit, MSTest, xUnit |
| Scenario | [assembly: Parallelizable(ParallelScope.Children)] | Individual scenarios, including scenarios from different features | NUnit, MSTest, TUnit |
Scenario scope finishes sooner when one feature holds most of the scenarios. The trade-off is that a feature's scenarios can land on different workers, so do not keep state in [BeforeFeature] hooks or FeatureContext at that scope.
Add [assembly: LevelOfParallelism(4)] to cap NUnit at four worker threads. Without it, NUnit uses Environment.ProcessorCount or 2, whichever is greater, according to the NUnit LevelOfParallelism reference.
Thread and Process Isolation
Reqnroll runs parallel tests as threads in one process and one application domain. Only thread-local state is isolated, and the binding registry of step definitions and hooks is shared, so your code must not write to static fields.
There is no AppDomain isolation. If a suite depends on static state you cannot remove, process isolation runs test threads in separate processes, which Reqnroll supports through VSTest per test assembly.
The static ScenarioContext.Current, FeatureContext.Current and ScenarioStepContext.Current properties are obsolete for the same reason. Accessing them during a parallel run throws a ReqnrollException:
// Throws ReqnrollException when scenarios run in parallel
private readonly ScenarioContext _scenarioContext = ScenarioContext.Current;
The Selenium C# 101 certification from TestMu AI covers the Selenium basics these step definitions build on:
Hooks in Reqnroll
Hooks run setup and cleanup code around test runs, features, scenarios and steps from any class marked [Binding]. In a parallel suite, scenario hooks are where each thread creates and releases its own browser. These are the hook types listed in the Reqnroll hooks reference:
| Hook attributes | Runs around | Must be static |
|---|---|---|
| [BeforeTestRun] / [AfterTestRun] | The whole test run (no tag filtering) | Yes |
| [BeforeFeature] / [AfterFeature] | Each feature | Yes |
| [BeforeScenario] / [AfterScenario] | Each scenario or scenario outline example | No |
| [BeforeScenarioBlock] / [AfterScenarioBlock] | Each Given, When or Then block | No |
| [BeforeStep] / [AfterStep] | Each step | No |
Hooks of the same type run in an unpredictable order unless you set Order. The lowest number runs first, and the default is 10000, so set it explicitly when one hook depends on another:
[BeforeScenario(Order = 0)]
public void StartBrowser() { /* runs first */ }
[BeforeScenario(Order = 10)]
public void SignIn() { /* runs after StartBrowser */ }
When a hook throws, later hooks of the same type are skipped, and a failing [BeforeScenario] marks the scenario's steps as skipped. [After] hooks still run, so check that a resource such as the driver was created before you clean it up.
The IObjectContainer
Context injection runs on BoDi, a small dependency injection container that ships inside Reqnroll as Reqnroll.BoDi. Each scenario gets its own container, so anything registered in it is scoped to that scenario's thread.
Plain classes need no registration. Use IObjectContainer when a binding asks for an interface, or when you want to hand over an instance you already built:
using Reqnroll;
using Reqnroll.BoDi;
[Binding]
public sealed class ContainerHooks
{
private readonly IObjectContainer _container;
public ContainerHooks(IObjectContainer container)
{
_container = container;
}
[BeforeScenario(Order = 0)]
public void RegisterServices()
{
// Bindings that ask for IAppUrls now receive a PlaygroundUrls instance
_container.RegisterTypeAs<PlaygroundUrls, IAppUrls>();
}
}
RegisterInstanceAs registers an existing object instead. It does not dispose that object unless you pass dispose: true, which matters when the object is a WebDriver that must quit.
This tutorial walks through the SpecFlow BDD framework with Selenium C#; the binding and hook concepts carry over to Reqnroll unchanged:
Demo: Parallel Reqnroll Scenarios With NUnit and Selenium 4
The project runs two features against the Selenium Playground Simple Form Demo. Each scenario outline row picks a browser, so five scenarios run at once across Chrome, Firefox and Edge on the TestMu AI grid.
Project Setup
Install the Reqnroll templates, create a project (the template uses NUnit by default) and add Selenium:
dotnet new install Reqnroll.Templates.DotNet
dotnet new reqnroll-project -n ReqnrollParallel
cd ReqnrollParallel
dotnet add package Selenium.WebDriver
dotnet add package Selenium.Support
The files added on top of the template:
- Features/SimpleForm.feature and Features/TwoInputFields.feature - the scenarios, with the browser as an outline column.
- Support/DriverContext.cs - creates one RemoteWebDriver per scenario and quits it on dispose.
- Support/Hooks.cs - reports each scenario's result to the TestMu AI dashboard.
- StepDefinitions/SimpleFormSteps.cs - the step bindings for both features.
- Parallel.cs - the NUnit assembly attributes that switch parallelism on.
Feature Files
Features/SimpleForm.feature types a message and checks that the page echoes it back:
Feature: Simple Form Demo
The Selenium Playground echoes a submitted message
Scenario Outline: Echo a message in <browser>
Given I open the Simple Form Demo in <browser>
When I submit the message "<message>"
Then the page shows the message "<message>"
Examples:
| browser | message |
| Chrome | Parallel run one |
| Firefox | Parallel run two |
| MicrosoftEdge | Parallel run three |
Features/TwoInputFields.feature adds two numbers on the same page:
Feature: Two Input Fields
The Selenium Playground adds two numbers
Scenario Outline: Add two numbers in <browser>
Given I open the Simple Form Demo in <browser>
When I add <first> and <second>
Then the page shows the sum "<total>"
Examples:
| browser | first | second | total |
| Chrome | 12 | 30 | 42 |
| Firefox | 7 | 8 | 15 |
Driver Context
The driver lives in a context-injected class, so each parallel scenario gets its own instance. Because the class implements IDisposable, Reqnroll quits the browser after the scenario without an explicit hook. The capabilities follow the Selenium 4 format from the TestMu AI C# Selenium documentation:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
namespace ReqnrollParallel.Support;
public sealed class DriverContext : IDisposable
{
public IWebDriver? Driver { get; private set; }
public IWebDriver Start(string browser, string testName)
{
DriverOptions options = browser switch
{
"Firefox" => new FirefoxOptions(),
"MicrosoftEdge" => new EdgeOptions(),
_ => new ChromeOptions()
};
options.BrowserVersion = "latest";
options.PlatformName = "Windows 11";
options.AddAdditionalOption("LT:Options", new Dictionary<string, object>
{
{ "username", Environment.GetEnvironmentVariable("LT_USERNAME")! },
{ "accessKey", Environment.GetEnvironmentVariable("LT_ACCESS_KEY")! },
{ "build", "Reqnroll NUnit Parallel" },
{ "name", testName },
{ "w3c", true }
});
Driver = new RemoteWebDriver(new Uri("https://hub.lambdatest.com/wd/hub"), options);
return Driver;
}
public void Dispose() => Driver?.Quit();
}
Support/Hooks.cs marks each session as passed or failed on the dashboard. It runs before Reqnroll disposes the driver context:
using OpenQA.Selenium;
using Reqnroll;
namespace ReqnrollParallel.Support;
[Binding]
public sealed class Hooks
{
private readonly DriverContext _driverContext;
private readonly ScenarioContext _scenarioContext;
public Hooks(DriverContext driverContext, ScenarioContext scenarioContext)
{
_driverContext = driverContext;
_scenarioContext = scenarioContext;
}
[AfterScenario(Order = 0)]
public void ReportStatus()
{
if (_driverContext.Driver is IJavaScriptExecutor js)
{
var status = _scenarioContext.TestError == null ? "passed" : "failed";
js.ExecuteScript("lambda-status=" + status);
}
}
}
Step Definitions
One binding class serves both features. It receives the scenario's driver context through its constructor, and the assertions wait for the text instead of sleeping:
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using Reqnroll;
using ReqnrollParallel.Support;
namespace ReqnrollParallel.StepDefinitions;
[Binding]
public sealed class SimpleFormSteps
{
private const string FormUrl = "https://www.testmuai.com/selenium-playground/simple-form-demo/";
private readonly DriverContext _driverContext;
private readonly ScenarioContext _scenarioContext;
public SimpleFormSteps(DriverContext driverContext, ScenarioContext scenarioContext)
{
_driverContext = driverContext;
_scenarioContext = scenarioContext;
}
private IWebDriver Driver => _driverContext.Driver!;
[Given("I open the Simple Form Demo in {word}")]
public void GivenIOpenTheSimpleFormDemoIn(string browser)
{
_driverContext.Start(browser, $"{_scenarioContext.ScenarioInfo.Title} ({browser})");
Driver.Navigate().GoToUrl(FormUrl);
}
[When("I submit the message {string}")]
public void WhenISubmitTheMessage(string message)
{
// Two elements on the page share id="user-message"; target the input
Driver.FindElement(By.CssSelector("input#user-message")).SendKeys(message);
Driver.FindElement(By.Id("showInput")).Click();
}
[When("I add {int} and {int}")]
public void WhenIAdd(int first, int second)
{
Driver.FindElement(By.Id("sum1")).SendKeys(first.ToString());
Driver.FindElement(By.Id("sum2")).SendKeys(second.ToString());
Driver.FindElement(By.XPath("//button[normalize-space()='Get Sum']")).Click();
}
[Then("the page shows the message {string}")]
public void ThenThePageShowsTheMessage(string expected) => AssertText("message", expected);
[Then("the page shows the sum {string}")]
public void ThenThePageShowsTheSum(string expected) => AssertText("addmessage", expected);
private void AssertText(string elementId, string expected)
{
var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
var shown = wait.Until(d =>
{
var text = d.FindElement(By.Id(elementId)).Text;
return text == expected ? text : null;
});
Assert.That(shown, Is.EqualTo(expected));
}
}
Run the Scenarios in Parallel
Parallel.cs turns on scenario-level scheduling and allows five workers, one per scenario. Keep the worker count at or below the parallel sessions your TestMu AI plan allows:
using NUnit.Framework;
[assembly: Parallelizable(ParallelScope.Children)]
[assembly: LevelOfParallelism(5)]
Set your credentials from the TestMu AI profile page and run the suite:
$env:LT_USERNAME = "your-username"
$env:LT_ACCESS_KEY = "your-access-key"
dotnet test
A selenium-webdriver (JavaScript) mirror of these five scenarios, with the same selectors, capabilities and hub URL, ran on the TestMu AI grid on October 23, 2026. All five sessions ran at once and passed:
Echo a message in Chrome passed "Parallel run one" 13.3 s
Echo a message in Firefox passed "Parallel run two" 21.9 s
Echo a message in MicrosoftEdge passed "Parallel run three" 13.3 s
Add two numbers in Chrome passed "42" 14.5 s
Add two numbers in Firefox passed "15" 23.2 s
Wall-clock time for all five sessions: 23.2 s
The five sessions add up to 86.2 seconds, so the parallel run finished in about a quarter of the serial time. The slowest session, Firefox, set the wall-clock time, which is why splitting slow scenarios across more workers pays off first.
For the NUnit side of these projects, including attributes, assertions and fixtures, this NUnit tutorial covers the framework with Selenium C#:
Note: TestMu AI runs Selenium C# suites like this one across 3,000+ browser and OS combinations in parallel, with full session artifacts for every run. Start testing for free.
Scaling Reqnroll Suites With HyperExecute
NUnit parallelism stops at one machine's worker threads. Once a suite has hundreds of scenarios, HyperExecute on TestMu AI spreads them across machines and runs suites up to 70% faster than traditional hub-and-node grids, because the test scripts and browsers run in the same isolated environment.
- Auto-Split - a discovery command lists your features or scenarios, and HyperExecute splits that list across the number of virtual machines set by concurrency, passing each entity to your dotnet test command through the $test placeholder.
- Matrix - runs one task per combination of the lists you declare, such as operating systems and browsers, which suits cross-browser regression of the same feature files.
- One report - each task runs in a fresh virtual machine, and the results come back as unified logs and reports with AI root cause analysis for failures.
The HyperExecute getting started guide covers the YAML file, the CLI and how to run the first job.
Next Steps
Start with [assembly: Parallelizable(ParallelScope.Fixtures)] on your existing suite, fix any scenario that fails only in parallel by moving its state into context injection, then switch to ParallelScope.Children. Point the driver context at the TestMu AI automation cloud to run those scenarios across browsers without maintaining a local grid.
Testing from the terminal? Kane CLI by TestMu AI lets SDETs and developers plan, write, run and debug tests from the command line.
Author
Himanshu Sheth is the Director of Marketing (Technical Content) at TestMu AI, with over 8 years of hands-on experience in Selenium, Cypress, and other test automation frameworks. He has authored more than 130 technical blogs for TestMu AI, covering software testing, automation strategy, and CI/CD. At TestMu AI, he leads the technical content efforts across blogs, YouTube, and social media, while closely collaborating with contributors to enhance content quality and product feedback loops. He has done his graduation with a B.E. in Computer Engineering from Mumbai University. Before TestMu AI, Himanshu led engineering teams in embedded software domains at companies like Samsung Research, Motorola, and NXP Semiconductors. He is a core member of DZone and has been a speaker at several unconferences focused on technical writing and software quality.
Reviewer
Srinivasan Sekar is Director of Engineering at TestMu AI, where he leads engineering and open-source initiatives behind the Selenium and Appium automation grid and owns TestMu AI's MCP Server. A committer to Appium and a contributor to Selenium, WebdriverIO, Taiko, and AppiumTestDistribution, he brings over 15 years of experience in quality engineering and open-source technologies. He is the author of the Apress book 'The MCP Standard: A Developer's Guide to Building Universal AI Tools with the Model Context Protocol,' a Certified Kubernetes and Cloud Native Associate, and an international conference speaker. Before TestMu AI he spent over eight years at Thoughtworks as a Principal Consultant and Quality Architect. Srinivasan holds a B.Tech in Information Technology from Anna University.
Reqnroll Parallel Execution FAQs
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance
- Advanced access controls
- Advanced data retention rules
- Advanced Local Testing
- Premium Support options
- Early access to beta features
- Private Slack Channel
- Unlimited Manual Accessibility DevTools Tests


















