Issue with ThreadStatic/AsyncLocal Variables Being Set to Null After Migrating from SpecFlow to Reqnroll (Playwright, NUnit) #469
-
Previously posted here: #428 I've tried to migrate to the suggested solution, using AsyncLocal variables however this gave me the same issue as when using ThreadStatic where the variables would be set to null as the thread has been killed. Ideally I don't want to be passing these variables down to my steps, pages and components for everything and wondered if there might be another solution on how to resolve this? As this isn't an issue when using SpecFlow, it's making the migration path to Reqnroll difficult. The ThreadStatic variables are used for the BrowserContext, Browser, ActivePage as an example of their uses and are used to differentiate between each NUnit thread when ran in parallel execution. Technology Used: .NET, Playwright, NUnit Description: I have tried both the compatibility migration and namespace migration, but the issue persists. Details:
Steps to Reproduce
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
SpecFlow (v3) was not really async. It used a hack to run the async hooks and step definitions from a sync context. SpecFlow v4 (never released) introduced real async handling and that (naturally) changed the behavior. In my opinion, using the So primarily I recommend to remove these constructs and build up the infrastructure without them. Using Following the logic of that, you cannot set an Reqnroll has a more correct async implementation now. As I wrote in the issue, you can study the related tests in Reqnroll: As I also wrote there, what you can do is to initialize the I hope this helps. |
Beta Was this translation helpful? Give feedback.
SpecFlow (v3) was not really async. It used a hack to run the async hooks and step definitions from a sync context. SpecFlow v4 (never released) introduced real async handling and that (naturally) changed the behavior.
In my opinion, using the
[ThreadStatic]
andAsyncLocal
for this purpose is a bad practice in general. As mentioned it in the related issue, you can have a look at our sample app (https://github.com/reqnroll/Sample-ReqOverflow/tree/main/ReqOverflow.Specs.WebUI) that solves all this without needing[ThreadStatic]
andAsyncLocal
.So primarily I recommend to remove these constructs and build up the infrastructure without them.
Using
AsyncLocal
does not work in the same way as[…