Skip to content

Commit

Permalink
Merge pull request #801 from bcgov/ricander
Browse files Browse the repository at this point in the history
Added webdriver constructor parameter for Headless operation in CICD …
  • Loading branch information
Richand101 authored Nov 19, 2024
2 parents 2131cea + a8390d7 commit 3397129
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:true);
webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

_Container.RegisterInstanceAs<SeleniumDriver>(webDriver);
Expand Down
1 change: 1 addition & 0 deletions Test/UITest/SpecFlowProjectBDD/SpecFlowProjectBDD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Selenium.Support" Version="4.16.2" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="130.0.6723.6900" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="131.0.2903.48" />
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageReference Include="SpecFlow.NUnit" Version="3.9.74" />
<PackageReference Include="nunit" Version="4.1.0" />
Expand Down
20 changes: 17 additions & 3 deletions Test/UITest/TestFrameWork/TestDriver/SeleniumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ public string Url

public ReadOnlyCollection<string> WindowHandles { get => Driver.WindowHandles; }

public SeleniumDriver(DRIVERTYPE DriverType)
/// <summary>
/// Create a Selenium webdriver for Chrome, Edge, or Firefox.
/// Requires that Nuget driver packages for the correct browser be installed in the solution/projects
/// </summary>
/// <param name="DriverType"></param>
/// <param name="Headless">Enable for headless CICD pipekine operation</param>
public SeleniumDriver(DRIVERTYPE DriverType, bool Headless = false)
{
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var assemblyDirectory = assembly.Location.Replace(assembly.ManifestModule.Name.ToString(), string.Empty);
Expand All @@ -50,14 +56,22 @@ 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;
}
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:
Expand Down
1 change: 1 addition & 0 deletions Test/UITest/TestFrameWork/TestFrameWork.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageReference Include="Selenium.Support" Version="4.16.2" />
<PackageReference Include="Selenium.WebDriver" Version="4.16.2" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="130.0.6723.6900" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="131.0.2903.48" />
</ItemGroup>

</Project>

0 comments on commit 3397129

Please sign in to comment.