diff --git a/src/Playwright.Xunit/BrowserTest.cs b/src/Playwright.Xunit/BrowserTest.cs index b8d4dba38..0540bfb17 100644 --- a/src/Playwright.Xunit/BrowserTest.cs +++ b/src/Playwright.Xunit/BrowserTest.cs @@ -48,7 +48,6 @@ public override async Task InitializeAsync() public override async Task DisposeAsync() { - await base.DisposeAsync().ConfigureAwait(false); if (TestOk) { foreach (var context in _contexts) @@ -58,5 +57,6 @@ public override async Task DisposeAsync() } _contexts.Clear(); Browser = null!; + await base.DisposeAsync().ConfigureAwait(false); } } diff --git a/src/Playwright.Xunit/Playwright.Xunit.csproj b/src/Playwright.Xunit/Playwright.Xunit.csproj index f51973e50..e33e22594 100644 --- a/src/Playwright.Xunit/Playwright.Xunit.csproj +++ b/src/Playwright.Xunit/Playwright.Xunit.csproj @@ -9,7 +9,7 @@ and fixtures to enable using it within xUnit. icon.png - net8.0 + netstandard2.0 true true Microsoft.Playwright.Xunit @@ -35,9 +35,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - diff --git a/src/Playwright.Xunit/WorkerAwareTest.cs b/src/Playwright.Xunit/WorkerAwareTest.cs index 3885a0755..1cce6b65e 100644 --- a/src/Playwright.Xunit/WorkerAwareTest.cs +++ b/src/Playwright.Xunit/WorkerAwareTest.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using Microsoft.Playwright.Core; @@ -34,10 +33,10 @@ namespace Microsoft.Playwright.Xunit; -public class WorkerAwareTest : ExceptionCapturer, IAsyncLifetime +public class WorkerAwareTest : ExceptionCapturer { private static readonly ConcurrentStack _allWorkers = new(); - private Worker? _currentWorker = null!; + private Worker _currentWorker = null!; internal class Worker { @@ -58,8 +57,9 @@ public async Task RegisterService(string name, Func> factory) wher return (_currentWorker.Services[name] as T)!; } - public virtual Task InitializeAsync() + async public override Task InitializeAsync() { + await base.InitializeAsync().ConfigureAwait(false); if (!_allWorkers.TryPop(out _currentWorker!)) { _currentWorker = new(); @@ -69,10 +69,9 @@ public virtual Task InitializeAsync() { AssertionsBase.SetDefaultTimeout(PlaywrightSettingsProvider.ExpectTimeout.Value); } - return Task.CompletedTask; } - public virtual async Task DisposeAsync() + public async override Task DisposeAsync() { if (TestOk) { @@ -90,6 +89,7 @@ public virtual async Task DisposeAsync() } _currentWorker.Services.Clear(); } + await base.DisposeAsync().ConfigureAwait(false); } } @@ -107,16 +107,26 @@ public interface IWorkerService /// Note: There is no way of getting the test status in xUnit in the dispose method. /// For more information, see: https://stackoverflow.com/questions/28895448/current-test-status-in-xunit-net /// -public class ExceptionCapturer +public class ExceptionCapturer : IAsyncLifetime { - protected static bool TestOk { get; private set; } = true; + protected bool TestOk { get; private set; } = true; - [ModuleInitializer] - public static void Setup() + public ExceptionCapturer() { AppDomain.CurrentDomain.FirstChanceException += (_, e) => { TestOk = false; }; } + + public virtual Task InitializeAsync() + { + TestOk = true; + return Task.CompletedTask; + } + + public virtual Task DisposeAsync() + { + return Task.CompletedTask; + } }