From 4231c56584440e282db7e10c3998e220aad5dced Mon Sep 17 00:00:00 2001 From: Rick Anderson Date: Tue, 19 Nov 2024 12:55:14 -0800 Subject: [PATCH 1/2] Added webdriver constructor parameter for Headless operation in CICD pipelines --- .../SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs | 2 +- .../UITest/TestFrameWork/TestDriver/SeleniumDriver.cs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Test/UITest/SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs b/Test/UITest/SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs index 77e6db46..9db31237 100644 --- a/Test/UITest/SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs +++ b/Test/UITest/SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs @@ -24,7 +24,7 @@ public SeleniumSpecFlowHooks(IObjectContainer container) public void SetupDrivers() { CleanupDrivers(); - SeleniumDriver webDriver = new SeleniumDriver(SeleniumDriver.DRIVERTYPE.CHROME); + SeleniumDriver webDriver = new SeleniumDriver(SeleniumDriver.DRIVERTYPE.CHROME, Headless:false); webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); _Container.RegisterInstanceAs(webDriver); diff --git a/Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs b/Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs index edf6b2a2..58f3c686 100644 --- a/Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs +++ b/Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs @@ -36,7 +36,13 @@ public string Url public ReadOnlyCollection WindowHandles { get => Driver.WindowHandles; } - public SeleniumDriver(DRIVERTYPE DriverType) + /// + /// Create a Selenium webdriver for Chrome, Edge, or Firefox. + /// Requires that Nuget driver packages for the correct browser be installed in the solution/projects + /// + /// + /// Enable for headless CICD pipekine operation + public SeleniumDriver(DRIVERTYPE DriverType, bool Headless = false) { var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var assemblyDirectory = assembly.Location.Replace(assembly.ManifestModule.Name.ToString(), string.Empty); @@ -50,7 +56,8 @@ public SeleniumDriver(DRIVERTYPE DriverType) options.AddArgument("--ignore-ssl-errors=yes"); options.AddArgument("--ignore-certificate-errors"); options.AddArgument("--start-maximized"); - //options.AddArgument("--headless"); + if(Headless) + options.AddArgument("--headless"); Driver = new ChromeDriver(assemblyDirectory, options); break; From a8390d7c1388cc72159c46d5e3b64246872fd5e9 Mon Sep 17 00:00:00 2001 From: Rick Anderson Date: Tue, 19 Nov 2024 13:56:17 -0800 Subject: [PATCH 2/2] Added Edge support --- .../SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs | 2 +- Test/UITest/SpecFlowProjectBDD/SpecFlowProjectBDD.csproj | 1 + Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs | 9 ++++++++- Test/UITest/TestFrameWork/TestFrameWork.csproj | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Test/UITest/SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs b/Test/UITest/SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs index 9db31237..4ec160fc 100644 --- a/Test/UITest/SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs +++ b/Test/UITest/SpecFlowProjectBDD/Hooks/SeleniumSpecFlowHooks.cs @@ -24,7 +24,7 @@ public SeleniumSpecFlowHooks(IObjectContainer container) public void SetupDrivers() { CleanupDrivers(); - SeleniumDriver webDriver = new SeleniumDriver(SeleniumDriver.DRIVERTYPE.CHROME, Headless:false); + SeleniumDriver webDriver = new SeleniumDriver(SeleniumDriver.DRIVERTYPE.CHROME, Headless:true); webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); _Container.RegisterInstanceAs(webDriver); diff --git a/Test/UITest/SpecFlowProjectBDD/SpecFlowProjectBDD.csproj b/Test/UITest/SpecFlowProjectBDD/SpecFlowProjectBDD.csproj index 9b0be6f3..408d33f6 100644 --- a/Test/UITest/SpecFlowProjectBDD/SpecFlowProjectBDD.csproj +++ b/Test/UITest/SpecFlowProjectBDD/SpecFlowProjectBDD.csproj @@ -42,6 +42,7 @@ + diff --git a/Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs b/Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs index 58f3c686..41df24b8 100644 --- a/Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs +++ b/Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs @@ -64,7 +64,14 @@ public SeleniumDriver(DRIVERTYPE DriverType, bool Headless = false) } case DRIVERTYPE.EDGE: { - Driver = new EdgeDriver(); + var options = new EdgeOptions(); + options.SetLoggingPreference(LogType.Driver, LogLevel.All); + options.AddArgument("--ignore-ssl-errors=yes"); + options.AddArgument("--ignore-certificate-errors"); + options.AddArgument("--start-maximized"); + if (Headless) + options.AddArgument("--headless"); + Driver = new EdgeDriver(assemblyDirectory, options); break; } case DRIVERTYPE.FIREFOX: diff --git a/Test/UITest/TestFrameWork/TestFrameWork.csproj b/Test/UITest/TestFrameWork/TestFrameWork.csproj index 43f51b94..91d0707d 100644 --- a/Test/UITest/TestFrameWork/TestFrameWork.csproj +++ b/Test/UITest/TestFrameWork/TestFrameWork.csproj @@ -10,6 +10,7 @@ +