diff --git a/src/Bellatrix.Playwright/infrastructure/App.cs b/src/Bellatrix.Playwright/infrastructure/App.cs index 5b0e008d3..4456f09ce 100644 --- a/src/Bellatrix.Playwright/infrastructure/App.cs +++ b/src/Bellatrix.Playwright/infrastructure/App.cs @@ -23,6 +23,7 @@ using Bellatrix.Playwright.Controls.EventHandlers; using Bellatrix.Playwright.Proxy; using Bellatrix.Playwright.Services; +using Bellatrix.Playwright.Services.Browser; using Bellatrix.Plugins; using Bellatrix.Utilities; @@ -35,6 +36,7 @@ public class App : IDisposable public App() { _apiClientService = GetNewApiClientService(); + AddShutdownHook(); } public BrowserService Browser => ServicesCollection.Current.Resolve(); @@ -159,4 +161,15 @@ public TPage GoTo() page.Open(); return page; } + + private void AddShutdownHook() + { + var container = ServicesCollection.Current; + var driver = container.Resolve(); + AppDomain.CurrentDomain.ProcessExit += new EventHandler((sender, eventArgs) => + { + DisposeBrowserService.Dispose(driver, container); + this.Dispose(); + }); + } } \ No newline at end of file diff --git a/src/Bellatrix.Web/infrastructure/App.cs b/src/Bellatrix.Web/infrastructure/App.cs index 6ca1352bd..83eb27230 100644 --- a/src/Bellatrix.Web/infrastructure/App.cs +++ b/src/Bellatrix.Web/infrastructure/App.cs @@ -38,6 +38,7 @@ public class App : IDisposable public App() { _apiClientService = GetNewApiClientService(); + AddShutdownHook(); } public BrowserService Browser => ServicesCollection.Current.Resolve(); @@ -216,4 +217,15 @@ private string DetermineTestClassFullNameAttributes() return fullClassName; } + + private void AddShutdownHook() + { + var container = ServicesCollection.Current; + var driver = container.Resolve(); + AppDomain.CurrentDomain.ProcessExit += new EventHandler((sender, eventArgs) => + { + DisposeDriverService.Dispose(driver, container); + this.Dispose(); + }); + } } \ No newline at end of file