mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Added initial Selenium E2E test setup
This commit is contained in:
45
tests/Berufsschule_HAM.E2ETests/Helper/AppHelper.cs
Normal file
45
tests/Berufsschule_HAM.E2ETests/Helper/AppHelper.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
|
||||
namespace Berufsschule_HAM.E2ETests.Helper;
|
||||
|
||||
public static class AppHelper
|
||||
{
|
||||
public static async Task<Process> StartApp(string appUrl)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "/snap/bin/dotnet",
|
||||
Arguments = "run --project ../../../../../src/",
|
||||
WorkingDirectory = AppContext.BaseDirectory,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
startInfo.EnvironmentVariables["ASPNETCORE_ENVIRONMENT"] = "Development";
|
||||
|
||||
|
||||
var process = new Process { StartInfo = startInfo };// Process process = Process.Start("/snap/bin/dotnet", "run -e Development");
|
||||
process.Start();
|
||||
using var client = new HttpClient();
|
||||
for (int i = 0; i < 60; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await client.GetAsync(appUrl);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return process;
|
||||
}
|
||||
else if (response.StatusCode != HttpStatusCode.RequestTimeout)
|
||||
{
|
||||
throw new Exception($"Server did not start properly? {response.StatusCode}");
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
throw new Exception("Server did not start within 60 seconds");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user