From 0a5204bba4c8ea0122990099818f0806173121f0 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva <133047546+MiriamKyoseva@users.noreply.github.com> Date: Tue, 16 Jul 2024 08:19:21 +0300 Subject: [PATCH 1/2] Added Shutdown Hooks for Opened Browsers --- src/Bellatrix.Playwright/infrastructure/App.cs | 12 ++++++++++++ src/Bellatrix.Web/infrastructure/App.cs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Bellatrix.Playwright/infrastructure/App.cs b/src/Bellatrix.Playwright/infrastructure/App.cs index 5b0e008d3..fb9850b57 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; @@ -159,4 +160,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 From 5a419bdd28c20e0653cc55ca098e88c9f15f18cd Mon Sep 17 00:00:00 2001 From: MiriamKyoseva <133047546+MiriamKyoseva@users.noreply.github.com> Date: Tue, 16 Jul 2024 08:24:18 +0300 Subject: [PATCH 2/2] Update App.cs --- src/Bellatrix.Playwright/infrastructure/App.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Bellatrix.Playwright/infrastructure/App.cs b/src/Bellatrix.Playwright/infrastructure/App.cs index fb9850b57..4456f09ce 100644 --- a/src/Bellatrix.Playwright/infrastructure/App.cs +++ b/src/Bellatrix.Playwright/infrastructure/App.cs @@ -36,6 +36,7 @@ public class App : IDisposable public App() { _apiClientService = GetNewApiClientService(); + AddShutdownHook(); } public BrowserService Browser => ServicesCollection.Current.Resolve();