Skip to content

Commit

Permalink
[dotnet] Propagate async throughout test setup and teardown (#14775)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenderMichael authored Nov 18, 2024
1 parent fe5b198 commit 0eb8393
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 44 deletions.
5 changes: 3 additions & 2 deletions dotnet/test/chrome/ChromeSpecificTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@

using NUnit.Framework;
using OpenQA.Selenium.Environment;
using System.Threading.Tasks;

namespace OpenQA.Selenium.Chrome
{
[TestFixture]
public class ChromeSpecificTests : DriverTestFixture
{
[OneTimeTearDown]
public void RunAfterAnyTests()
public async Task RunAfterAnyTestsAsync()
{
EnvironmentManager.Instance.CloseCurrentDriver();
EnvironmentManager.Instance.WebServer.Stop();
await EnvironmentManager.Instance.WebServer.StopAsync();
}
}
}
13 changes: 7 additions & 6 deletions dotnet/test/common/AssemblyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using NUnit.Framework;
using OpenQA.Selenium.Environment;
using System.Threading.Tasks;

namespace OpenQA.Selenium
{
Expand All @@ -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();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/test/common/Environment/EnvironmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ private EnvironmentManager()
{
if (remoteServer != null)
{
remoteServer.Stop();
remoteServer.StopAsync().Wait();
}
if (webServer != null)
{
webServer.Stop();
webServer.StopAsync().Wait();
}
CloseCurrentDriver();
}
Expand Down
9 changes: 5 additions & 4 deletions dotnet/test/common/Environment/RemoteSeleniumServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace OpenQA.Selenium.Environment
{
Expand All @@ -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))
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -86,15 +87,15 @@ public void Start()
}
}

public void Stop()
public async Task StopAsync()
{
if (autoStart && webserverProcess != null && !webserverProcess.HasExited)
{
using var httpClient = new HttpClient();

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)
{
Expand Down
9 changes: 5 additions & 4 deletions dotnet/test/common/Environment/TestWebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace OpenQA.Selenium.Environment
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -174,15 +175,15 @@ public void Start()
}
}

public void Stop()
public async Task StopAsync()
{
if (webserverProcess != null)
{
using (var httpClient = new HttpClient())
{
try
{
using (httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("quitquitquit")).GetAwaiter().GetResult())
using (await httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("quitquitquit")))
{

}
Expand Down
9 changes: 5 additions & 4 deletions dotnet/test/edge/AssemblyTeardown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using NUnit.Framework;
using OpenQA.Selenium.Environment;
using System.Threading.Tasks;

namespace OpenQA.Selenium.Edge
{
Expand All @@ -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();
}
}
}
9 changes: 5 additions & 4 deletions dotnet/test/firefox/AssemblyTeardown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using NUnit.Framework;
using OpenQA.Selenium.Environment;
using System.Threading.Tasks;

namespace OpenQA.Selenium.Firefox
{
Expand All @@ -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();
}
}
}
9 changes: 5 additions & 4 deletions dotnet/test/ie/AssemblyTeardown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using NUnit.Framework;
using OpenQA.Selenium.Environment;
using System.Threading.Tasks;

namespace OpenQA.Selenium.IE
{
Expand All @@ -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();
}
}
}
13 changes: 7 additions & 6 deletions dotnet/test/remote/AssemblyTeardown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using NUnit.Framework;
using OpenQA.Selenium.Environment;
using System.Threading.Tasks;

namespace OpenQA.Selenium.Remote
{
Expand All @@ -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();
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions dotnet/test/support/UI/PopupWindowFinderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using NUnit.Framework;
using OpenQA.Selenium.Environment;
using System.Threading.Tasks;

namespace OpenQA.Selenium.Support.UI
{
Expand All @@ -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]
Expand Down
9 changes: 5 additions & 4 deletions dotnet/test/support/UI/SelectBrowserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,24 @@
using OpenQA.Selenium.Environment;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OpenQA.Selenium.Support.UI
{
[TestFixture]
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]
Expand Down

0 comments on commit 0eb8393

Please sign in to comment.