using System.Diagnostics; using System.Net; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; namespace Berufsschule_HAM.E2ETests.Helper; public static class AppHelper { public static async Task 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"); } public static void Login(ChromeDriver driver, string serverUrl) { driver.Navigate().GoToUrl(serverUrl); IWebElement username = driver.FindElement(By.Id("username")); username.SendKeys("admin"); IWebElement password = driver.FindElement(By.Id("password")); password.SendKeys("Test1234."); IWebElement submit = driver.FindElement(By.CssSelector("button[type=\"submit\"]")); submit.Click(); Thread.Sleep(250); } }