You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To give a brief context, we are using ExtentReports for our playwright tests with reqnroll & using DI to capture and show info/warning logs on the extentreport.
public class ExtentTestManager : IExtentTestManager
{
public static AsyncLocal<ExtentTest> _asyncLocalExtentTest = new AsyncLocal<ExtentTest>();
public void SetCurrentTest(ExtentTest test)
{
Console.WriteLine($"SetCurrentTest called in thread: {Environment.CurrentManagedThreadId}");
_asyncLocalExtentTest.Value = test;
}
public ExtentTest GetCurrentTest()
{
Console.WriteLine($"GetCurrentTest called in thread: {Environment.CurrentManagedThreadId}");
return _asyncLocalExtentTest.Value;
}
}
Register ExtentTestManager in Startup.cs
public class Startup
{
[ScenarioDependencies]
public static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services
.AddScoped<IExtentTestManager, ExtentTestManager>();
return services;
}
}
Inject IExtentTestManager into Page Classes as below
public class LoginPage
{
private readonly IExtentTestManager _extentTestManager;
public LoginPage(IExtentTestManager extentTestManager)
{
_extentTestManager = extentTestManager;
}
public void PerformLogin(string username, string password)
{
var extentTest = _extentTestManager.GetCurrentTest();
extentTest .Log(Status.Info,"Login page is displayed");
}
}
In Step 4, extentTest value returns null.
Clarifications Needed:
We currently notice that ExtentTest thread and Nunit test thread run on different threads hence causing the issue, This happens even though we are using Before Scenario to initialize ExtentTest
How do we make sure if our test execution framework (e.g., NUnit here) runs scenario setup and execution on the same thread ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi All -
Background:
To give a brief context, we are using ExtentReports for our playwright tests with reqnroll & using DI to capture and show info/warning logs on the extentreport.
}
In Step 4, extentTest value returns null.
Clarifications Needed:
We currently notice that ExtentTest thread and Nunit test thread run on different threads hence causing the issue, This happens even though we are using
Before Scenario
to initialize ExtentTestHow do we make sure if our test execution framework (e.g., NUnit here) runs scenario setup and execution on the same thread ?
Beta Was this translation helpful? Give feedback.
All reactions