0

Does anyone have successfully setup a beforetestrun/aftertestrun hook when using Specflow runner on multithread using AppDomain I saw some answer from this thread - Run BeforeTestRun and AfterTestRun only once using specflow with Selenium

Unfortunately, I'm having difficulty to set this up as we need it to configure our TestRail integration.

1 Answers1

0

It is possible - you have to use a kernel-based lock (the following constructor is the one to use): https://learn.microsoft.com/en-us/dotnet/api/system.threading.semaphore.-ctor?view=net-5.0#System_Threading_Semaphore__ctor_System_Int32_System_Int32_System_String_System_Boolean__

The flow:

  1. Create a named instance of Semaphore
  2. The thread where createdNew == true is the first thread that entered the code - execute test run init code here
  3. For other threads use method 'WaitOne' with a proper timeout

Best regards, PM

Piotr M.
  • 385
  • 2
  • 8