Unable to access test execution dependent service 'Reqnroll.TestThreadContext' with the Reqnroll.Microsoft.Extensions.DependencyInjection plugin #562
-
Reqnroll Version2.4.0 Which test runner are you using?MSTest Test Runner Version Number2.4.0 .NET Implementation.NET 8.0 Test Execution MethodVisual Studio Test Explorer Content of reqnroll.json configuration file{
"$schema": "https://schemas.reqnroll.net/reqnroll-config-latest.json",
"bindingAssemblies": [
{
"assembly": "Credentials.UI.Integration.Tests"
}
]
} Issue DescriptionWhile converting specflow tests to Reqnroll, I came across this exception. The same has worked fine with specflow but somehow vausing triuble when migrated tests from specflow to reqnroll. Build worked fine. Issue while running scripts. Error: Unable to access test execution dependent service 'Reqnroll.TestThreadContext' with the Reqnroll.Microsoft.Extensions.DependencyInjection plugin. This service is only available once test execution has been started and cannot be used in '[BeforeTestRun]' hook. Any help would be much appreciated. Below is the code written for hooks.cs [Binding]
public sealed class Hooks
{
private static TestContext _testContext;
public Hooks()
{
}
[BeforeTestRun]
public static void BeforeTestRun(TestThreadContext threadContext, IConfiguration configuration)
{
_testContext= threadContext.TestThreadContainer.Resolve<TestContext>();
if (_testContext.Properties.Contains("Environment") &&
_testContext.Properties["Environment"].ToString() == "dev")
{
threadContext.Add("portal", configuration["portal:url"]);
}
else
{
}
}
[AfterScenario]
public void AfterScenario(BrowserDriver browserDriver)
{
browserDriver.Current.Close();
browserDriver.Current.Quit();
}
}
} Steps to Reproduce
Link to Repro ProjectNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
For the TestContext you could use parameter injection: [BeforeTestRun]
public static void BeforeTestRun (TestContext testContext)
{
if (testContext.Properties.Contains ("Environment") &&
testContext.Properties["Environment"].ToString () == "dev")
{
threadContext.Add ("portal", configuration["portal:url"]);
}
} see https://docs.reqnroll.net/latest/integrations/mstest.html#accessing-testcontext for the TestThreadContext if have to search |
Beta Was this translation helpful? Give feedback.
For the TestContext you could use parameter injection:
see https://docs.reqnroll.net/latest/integrations/mstest.html#accessing-testcontext
for the TestThreadContext if have to search