From 0eb839371479062896d97611cfff4bdbf6b43de5 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Mon, 18 Nov 2024 16:48:39 -0500 Subject: [PATCH] [dotnet] Propagate async throughout test setup and teardown (#14775) --- dotnet/test/chrome/ChromeSpecificTests.cs | 5 +++-- dotnet/test/common/AssemblyFixture.cs | 13 +++++++------ .../test/common/Environment/EnvironmentManager.cs | 4 ++-- .../test/common/Environment/RemoteSeleniumServer.cs | 9 +++++---- dotnet/test/common/Environment/TestWebServer.cs | 9 +++++---- dotnet/test/edge/AssemblyTeardown.cs | 9 +++++---- dotnet/test/firefox/AssemblyTeardown.cs | 9 +++++---- dotnet/test/ie/AssemblyTeardown.cs | 9 +++++---- dotnet/test/remote/AssemblyTeardown.cs | 13 +++++++------ dotnet/test/support/UI/PopupWindowFinderTest.cs | 9 +++++---- dotnet/test/support/UI/SelectBrowserTests.cs | 9 +++++---- 11 files changed, 54 insertions(+), 44 deletions(-) diff --git a/dotnet/test/chrome/ChromeSpecificTests.cs b/dotnet/test/chrome/ChromeSpecificTests.cs index 40b4faeff3811..a0cc07f28ea04 100644 --- a/dotnet/test/chrome/ChromeSpecificTests.cs +++ b/dotnet/test/chrome/ChromeSpecificTests.cs @@ -19,6 +19,7 @@ using NUnit.Framework; using OpenQA.Selenium.Environment; +using System.Threading.Tasks; namespace OpenQA.Selenium.Chrome { @@ -26,10 +27,10 @@ namespace OpenQA.Selenium.Chrome public class ChromeSpecificTests : DriverTestFixture { [OneTimeTearDown] - public void RunAfterAnyTests() + public async Task RunAfterAnyTestsAsync() { EnvironmentManager.Instance.CloseCurrentDriver(); - EnvironmentManager.Instance.WebServer.Stop(); + await EnvironmentManager.Instance.WebServer.StopAsync(); } } } diff --git a/dotnet/test/common/AssemblyFixture.cs b/dotnet/test/common/AssemblyFixture.cs index fda821c9ea304..aacc1b2a7d573 100644 --- a/dotnet/test/common/AssemblyFixture.cs +++ b/dotnet/test/common/AssemblyFixture.cs @@ -19,6 +19,7 @@ using NUnit.Framework; using OpenQA.Selenium.Environment; +using System.Threading.Tasks; namespace OpenQA.Selenium { @@ -31,25 +32,25 @@ public AssemblyFixture() } [OneTimeSetUp] - public void RunBeforeAnyTest() + public async Task RunBeforeAnyTestAsync() { Internal.Logging.Log.SetLevel(Internal.Logging.LogEventLevel.Trace); - EnvironmentManager.Instance.WebServer.Start(); + await EnvironmentManager.Instance.WebServer.StartAsync(); if (EnvironmentManager.Instance.Browser == Browser.Remote) { - EnvironmentManager.Instance.RemoteServer.Start(); + await EnvironmentManager.Instance.RemoteServer.StartAsync(); } } [OneTimeTearDown] - public void RunAfterAnyTests() + public async Task RunAfterAnyTestsAsync() { EnvironmentManager.Instance.CloseCurrentDriver(); - EnvironmentManager.Instance.WebServer.Stop(); + await EnvironmentManager.Instance.WebServer.StopAsync(); if (EnvironmentManager.Instance.Browser == Browser.Remote) { - EnvironmentManager.Instance.RemoteServer.Stop(); + await EnvironmentManager.Instance.RemoteServer.StopAsync(); } } } diff --git a/dotnet/test/common/Environment/EnvironmentManager.cs b/dotnet/test/common/Environment/EnvironmentManager.cs index 20653378c27e8..9c0b53b90c56c 100644 --- a/dotnet/test/common/Environment/EnvironmentManager.cs +++ b/dotnet/test/common/Environment/EnvironmentManager.cs @@ -199,11 +199,11 @@ private EnvironmentManager() { if (remoteServer != null) { - remoteServer.Stop(); + remoteServer.StopAsync().Wait(); } if (webServer != null) { - webServer.Stop(); + webServer.StopAsync().Wait(); } CloseCurrentDriver(); } diff --git a/dotnet/test/common/Environment/RemoteSeleniumServer.cs b/dotnet/test/common/Environment/RemoteSeleniumServer.cs index 80d3c27e5e0bc..388bc6b1e3083 100644 --- a/dotnet/test/common/Environment/RemoteSeleniumServer.cs +++ b/dotnet/test/common/Environment/RemoteSeleniumServer.cs @@ -22,6 +22,7 @@ using System.IO; using System.Net; using System.Net.Http; +using System.Threading.Tasks; namespace OpenQA.Selenium.Environment { @@ -38,7 +39,7 @@ public RemoteSeleniumServer(string projectRoot, bool autoStartServer) autoStart = autoStartServer; } - public void Start() + public async Task StartAsync() { if (autoStart && (webserverProcess == null || webserverProcess.HasExited)) { @@ -67,7 +68,7 @@ public void Start() { try { - using var response = httpClient.GetAsync("http://localhost:6000/wd/hub/status").GetAwaiter().GetResult(); + using var response = await httpClient.GetAsync("http://localhost:6000/wd/hub/status"); if (response.StatusCode == HttpStatusCode.OK) { @@ -86,7 +87,7 @@ public void Start() } } - public void Stop() + public async Task StopAsync() { if (autoStart && webserverProcess != null && !webserverProcess.HasExited) { @@ -94,7 +95,7 @@ public void Stop() try { - using var response = httpClient.GetAsync("http://localhost:6000/selenium-server/driver?cmd=shutDownSeleniumServer").GetAwaiter().GetResult(); + using var response = await httpClient.GetAsync("http://localhost:6000/selenium-server/driver?cmd=shutDownSeleniumServer"); } catch (Exception ex) when (ex is HttpRequestException || ex is TimeoutException) { diff --git a/dotnet/test/common/Environment/TestWebServer.cs b/dotnet/test/common/Environment/TestWebServer.cs index b47585cd3c312..f5fcd0f4ff0c6 100644 --- a/dotnet/test/common/Environment/TestWebServer.cs +++ b/dotnet/test/common/Environment/TestWebServer.cs @@ -25,6 +25,7 @@ using System.Net.Http; using System.Runtime.InteropServices; using System.Text; +using System.Threading.Tasks; namespace OpenQA.Selenium.Environment { @@ -50,7 +51,7 @@ public TestWebServer(string projectRoot, TestWebServerConfig config) this.port = config.Port; } - public void Start() + public async Task StartAsync() { if (webserverProcess == null || webserverProcess.HasExited) { @@ -146,7 +147,7 @@ public void Start() { try { - using var response = httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("simpleTest.html")).GetAwaiter().GetResult(); + using var response = await httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("simpleTest.html")); if (response.StatusCode == HttpStatusCode.OK) { @@ -174,7 +175,7 @@ public void Start() } } - public void Stop() + public async Task StopAsync() { if (webserverProcess != null) { @@ -182,7 +183,7 @@ public void Stop() { try { - using (httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("quitquitquit")).GetAwaiter().GetResult()) + using (await httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("quitquitquit"))) { } diff --git a/dotnet/test/edge/AssemblyTeardown.cs b/dotnet/test/edge/AssemblyTeardown.cs index 6b8c737e61bbe..ff9875f8f9c00 100644 --- a/dotnet/test/edge/AssemblyTeardown.cs +++ b/dotnet/test/edge/AssemblyTeardown.cs @@ -19,6 +19,7 @@ using NUnit.Framework; using OpenQA.Selenium.Environment; +using System.Threading.Tasks; namespace OpenQA.Selenium.Edge { @@ -27,16 +28,16 @@ namespace OpenQA.Selenium.Edge public class MySetUpClass { [OneTimeSetUp] - public void RunBeforeAnyTest() + public async Task RunBeforeAnyTestAsync() { - EnvironmentManager.Instance.WebServer.Start(); + await EnvironmentManager.Instance.WebServer.StartAsync(); } [OneTimeTearDown] - public void RunAfterAnyTests() + public async Task RunAfterAnyTestsAsync() { EnvironmentManager.Instance.CloseCurrentDriver(); - EnvironmentManager.Instance.WebServer.Stop(); + await EnvironmentManager.Instance.WebServer.StopAsync(); } } } diff --git a/dotnet/test/firefox/AssemblyTeardown.cs b/dotnet/test/firefox/AssemblyTeardown.cs index 4e0438f44aca7..a0423752a63f5 100644 --- a/dotnet/test/firefox/AssemblyTeardown.cs +++ b/dotnet/test/firefox/AssemblyTeardown.cs @@ -19,6 +19,7 @@ using NUnit.Framework; using OpenQA.Selenium.Environment; +using System.Threading.Tasks; namespace OpenQA.Selenium.Firefox { @@ -27,16 +28,16 @@ namespace OpenQA.Selenium.Firefox public class MySetUpClass { [OneTimeSetUp] - public void RunBeforeAnyTest() + public async Task RunBeforeAnyTestAsync() { - EnvironmentManager.Instance.WebServer.Start(); + await EnvironmentManager.Instance.WebServer.StartAsync(); } [OneTimeTearDown] - public void RunAfterAnyTests() + public async Task RunAfterAnyTestsAsync() { EnvironmentManager.Instance.CloseCurrentDriver(); - EnvironmentManager.Instance.WebServer.Stop(); + await EnvironmentManager.Instance.WebServer.StopAsync(); } } } diff --git a/dotnet/test/ie/AssemblyTeardown.cs b/dotnet/test/ie/AssemblyTeardown.cs index d2780925484f3..d720502b6e112 100644 --- a/dotnet/test/ie/AssemblyTeardown.cs +++ b/dotnet/test/ie/AssemblyTeardown.cs @@ -19,6 +19,7 @@ using NUnit.Framework; using OpenQA.Selenium.Environment; +using System.Threading.Tasks; namespace OpenQA.Selenium.IE { @@ -27,16 +28,16 @@ namespace OpenQA.Selenium.IE public class MySetUpClass { [OneTimeSetUp] - public void RunBeforeAnyTest() + public async Task RunBeforeAnyTestAsync() { - EnvironmentManager.Instance.WebServer.Start(); + await EnvironmentManager.Instance.WebServer.StartAsync(); } [OneTimeTearDown] - public void RunAfterAnyTests() + public async Task RunAfterAnyTestsAsync() { EnvironmentManager.Instance.CloseCurrentDriver(); - EnvironmentManager.Instance.WebServer.Stop(); + await EnvironmentManager.Instance.WebServer.StopAsync(); } } } diff --git a/dotnet/test/remote/AssemblyTeardown.cs b/dotnet/test/remote/AssemblyTeardown.cs index a9fc17ea13a2d..aca281e6ee801 100644 --- a/dotnet/test/remote/AssemblyTeardown.cs +++ b/dotnet/test/remote/AssemblyTeardown.cs @@ -19,6 +19,7 @@ using NUnit.Framework; using OpenQA.Selenium.Environment; +using System.Threading.Tasks; namespace OpenQA.Selenium.Remote { @@ -27,23 +28,23 @@ namespace OpenQA.Selenium.Remote public class MySetUpClass { [OneTimeSetUp] - public void RunBeforeAnyTest() + public async Task RunBeforeAnyTestAsync() { - EnvironmentManager.Instance.WebServer.Start(); + await EnvironmentManager.Instance.WebServer.StartAsync(); if (EnvironmentManager.Instance.Browser == Browser.Remote) { - EnvironmentManager.Instance.RemoteServer.Start(); + await EnvironmentManager.Instance.RemoteServer.StartAsync(); } } [OneTimeTearDown] - public void RunAfterAnyTests() + public async Task RunAfterAnyTestsAsync() { EnvironmentManager.Instance.CloseCurrentDriver(); - EnvironmentManager.Instance.WebServer.Stop(); + await EnvironmentManager.Instance.WebServer.StopAsync(); if (EnvironmentManager.Instance.Browser == Browser.Remote) { - EnvironmentManager.Instance.RemoteServer.Stop(); + await EnvironmentManager.Instance.RemoteServer.StopAsync(); } } } diff --git a/dotnet/test/support/UI/PopupWindowFinderTest.cs b/dotnet/test/support/UI/PopupWindowFinderTest.cs index bbbf910d15969..692fa8d19e1bb 100644 --- a/dotnet/test/support/UI/PopupWindowFinderTest.cs +++ b/dotnet/test/support/UI/PopupWindowFinderTest.cs @@ -19,6 +19,7 @@ using NUnit.Framework; using OpenQA.Selenium.Environment; +using System.Threading.Tasks; namespace OpenQA.Selenium.Support.UI { @@ -27,16 +28,16 @@ public class PopupWindowFinderTest : DriverTestFixture { //TODO: Move these to a standalone class when more tests rely on the server being up [OneTimeSetUp] - public void RunBeforeAnyTest() + public async Task RunBeforeAnyTestAsync() { - EnvironmentManager.Instance.WebServer.Start(); + await EnvironmentManager.Instance.WebServer.StartAsync(); } [OneTimeTearDown] - public void RunAfterAnyTests() + public async Task RunAfterAnyTestsAsync() { EnvironmentManager.Instance.CloseCurrentDriver(); - EnvironmentManager.Instance.WebServer.Stop(); + await EnvironmentManager.Instance.WebServer.StopAsync(); } [Test] diff --git a/dotnet/test/support/UI/SelectBrowserTests.cs b/dotnet/test/support/UI/SelectBrowserTests.cs index 38c1a9d29f933..fc835d96a4596 100644 --- a/dotnet/test/support/UI/SelectBrowserTests.cs +++ b/dotnet/test/support/UI/SelectBrowserTests.cs @@ -21,6 +21,7 @@ using OpenQA.Selenium.Environment; using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace OpenQA.Selenium.Support.UI { @@ -28,16 +29,16 @@ namespace OpenQA.Selenium.Support.UI public class SelectBrowserTests : DriverTestFixture { [OneTimeSetUp] - public void RunBeforeAnyTest() + public async Task RunBeforeAnyTestAsync() { - EnvironmentManager.Instance.WebServer.Start(); + await EnvironmentManager.Instance.WebServer.StartAsync(); } [OneTimeTearDown] - public void RunAfterAnyTests() + public async Task RunAfterAnyTestsAsync() { EnvironmentManager.Instance.CloseCurrentDriver(); - EnvironmentManager.Instance.WebServer.Stop(); + await EnvironmentManager.Instance.WebServer.StopAsync(); } [SetUp]