In an existing SpecFlow project, inject ScenarioContext into a binding class or scenario-level hook, then use that instance to share data between steps in the same scenario. Avoid ScenarioContext.Current in SpecFlow 3 or later. SpecFlow reached end of life on December 31, 2024; for new work, evaluate Reqnroll and check its current migration guidance and package compatibility.
What ScenarioContext is for
ScenarioContext represents the active scenario. It can hold temporary test data that one step writes and another step reads, including when those steps belong to separate binding classes. It is test-execution state, not durable application storage.
As an Amazon Associate I earn from qualifying purchases.
Use it for a value that is genuinely shared within one scenario. For long workflows, prefer focused scenarios and explicit setup so that a large collection of hidden, string-keyed dependencies does not make tests difficult to understand.
Inject ScenarioContext into a binding
Constructor injection makes the dependency visible and gives the binding access to the context for its active scenario. This illustrative C# pattern stores a customer name in one step and reads it in another:
#1 Best Overall
using TechTalk.SpecFlow;
[Binding]
public class AccountSteps
{
private readonly ScenarioContext _scenarioContext;
public AccountSteps(ScenarioContext scenarioContext)
{
_scenarioContext = scenarioContext;
}
[Given("I have a customer")]
public void GivenIHaveACustomer()
{
_scenarioContext["customer"] = "Ada";
}
[Then("the customer is available")]
public void ThenTheCustomerIsAvailable()
{
var customer = (string)_scenarioContext["customer"];
// Assert or otherwise use customer here.
}
}
Use descriptive, consistent keys, and write the value before any step attempts to read it. In a real test, add an assertion appropriate to the behavior being checked; the example only demonstrates storing and retrieving scenario data.
Use the context only where a scenario is active
Scenario- and step-level hooks run in an active scenario and can receive its context. Test-run and feature-level hooks run without an active scenario, so they cannot use that scenario’s ScenarioContext. Scenario metadata such as title and tags is available through ScenarioContext.ScenarioInfo.
Rank #2
If information must be shared across scenarios in the same feature, consider FeatureContext instead. Do not substitute static shared state without considering parallel execution: scenarios running concurrently can interfere with one another when they mutate shared data.
Choose the right place for test state
| Need | Approach | Scope and trade-off |
|---|---|---|
| Pass temporary data between steps in one scenario | Injected ScenarioContext |
Scoped to the active scenario; useful across binding classes, but opaque keys can hide dependencies. |
| Share data across scenarios within a feature | FeatureContext |
Feature-wide rather than scenario-wide; consider interactions and parallel execution. |
| Make a scenario’s prerequisites easy to understand | Explicit step inputs and focused scenario setup | Reduces hidden coupling and the accumulation of unrelated values in a context property bag. |
Do not use ScenarioContext.Current in new code
ScenarioContext.Current was marked obsolete in SpecFlow 3.0 and later. Prefer injecting the context, especially in suites that may run scenarios in parallel. Constructor injection also makes a binding’s use of scenario state explicit instead of relying on legacy static access.
Account for SpecFlow’s end of life
Tricentis ended SpecFlow on December 31, 2024. Reqnroll is described as retaining the ScenarioContext and FeatureContext APIs, with the namespace changing from TechTalk.SpecFlow to Reqnroll. Treat that as a migration starting point, not a guarantee that an existing suite will work unchanged: consult current Reqnroll migration documentation and verify package compatibility for your project before switching.
Troubleshoot common problems
- A read fails or returns no useful value: check that a prior step stored the value under the same key, with the expected type, before the read occurs.
- A hook cannot obtain ScenarioContext: check its scope. Test-run and feature hooks do not have an active scenario context; use a scenario- or step-level hook for scenario state.
- Tests interfere when run in parallel: remove shared static mutable state and use scenario-scoped injection for values that belong to one scenario.
- A SpecFlow project fails after a framework or package upgrade: do not assume end-of-life SpecFlow code is compatible with current .NET or Reqnroll packages. Check the migration documentation and package compatibility, then resolve namespace and dependency changes deliberately.
- A context has become hard to maintain: replace unrelated or implicit key-value dependencies with focused scenarios and explicit setup where practical.
Or skip the browser setup
If your testing work also needs website captures, ScreenshotNeo is a separate website screenshot API and MCP server for developers—not a replacement for SpecFlow’s scenario state. Its API can return a screenshot or PDF from one GET request. The following cURL example saves a WebP capture; see the ScreenshotNeo API documentation for options and response details.
Rank #4
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchSign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




