From f36038910a4b3af874991dd71e002b006e3f9ff9 Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 23 Dec 2021 00:23:14 -0500 Subject: [PATCH] Run ChromeDriver in headless mode if in a CI environment --- .../AuthenticationTests.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse.Tests.WebsiteTests/AuthenticationTests.cs b/ProjectLighthouse.Tests.WebsiteTests/AuthenticationTests.cs index ce7f7f74..5266abf4 100644 --- a/ProjectLighthouse.Tests.WebsiteTests/AuthenticationTests.cs +++ b/ProjectLighthouse.Tests.WebsiteTests/AuthenticationTests.cs @@ -19,7 +19,7 @@ namespace ProjectLighthouse.Tests.WebsiteTests public readonly IWebHost WebHost = new WebHostBuilder().UseKestrel().UseStartup().UseWebRoot("StaticFiles").Build(); public readonly string BaseAddress; - public readonly IWebDriver Driver = new ChromeDriver(); + public readonly IWebDriver Driver; public AuthenticationTests() { @@ -29,6 +29,15 @@ namespace ProjectLighthouse.Tests.WebsiteTests if (serverAddressesFeature == null) throw new ArgumentNullException(); this.BaseAddress = serverAddressesFeature.Addresses.First(); + + ChromeOptions chromeOptions = new(); + if (Convert.ToBoolean(Environment.GetEnvironmentVariable("CI") ?? "false")) + { + chromeOptions.AddArgument("headless"); + Console.WriteLine("We are in a CI environment, so chrome headless mode has been enabled."); + } + + this.Driver = new ChromeDriver(chromeOptions); } [DatabaseFact]