Skip to content

Commit

Permalink
feat: additional capabilities (#131)
Browse files Browse the repository at this point in the history
Additional capabilities are often required to support the use of managed Selenium Grid services (e.g. account details are often passed this way).

Consumers using their own Selenium Grids may also see some benefits to being able to pass these as well.
  • Loading branch information
ewingjm authored Aug 5, 2022
1 parent dcc353e commit 4ce4d28
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ browserOptions: # optional - will use default EasyRepro options if not set
height: 1080
startMaximized: false
driversPath: ChromeWebDriver # optional - [Recommended when running tests from Azure DevOps Microsoft-hosted agent](https://docs.microsoft.com/en-us/azure/devops/pipelines/test/continuous-test-selenium?view=azure-devops#decide-how-you-will-deploy-and-test-your-app)
additionalCapabilities: # optional - additional capabilities to pass to the WebDriver
capabilityName: capabilityValue
applicationUser: # optional - populate if creating test data for users other than the current user
tenantId: SPECFLOW_POWERAPPS_TENANTID optional # mandatory
clientId: SPECFLOW_POWERAPPS_CLIENTID # mandatory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
namespace Capgemini.PowerApps.SpecFlowBindings.Configuration
{
using System;
using System.Collections.Generic;
using System.IO;
using Capgemini.PowerApps.SpecFlowBindings.Extensions;
using Microsoft.Dynamics365.UIAutomation.Browser;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;

/// <summary>
/// Extends the EasyRepro <see cref="BrowserOptions"/> class with additonal support for chrome profiles.
/// Extends the EasyRepro <see cref="BrowserOptions"/> class with support for additional configuration.
/// </summary>
public class BrowserOptionsWithProfileSupport : BrowserOptions, ICloneable
{
/// <summary>
/// Initializes a new instance of the <see cref="BrowserOptionsWithProfileSupport"/> class.
/// </summary>
public BrowserOptionsWithProfileSupport()
: base()
{
this.AdditionalCapabilities = new Dictionary<string, object>();
}

/// <summary>
/// Gets or sets the directory to use as the user profile.
/// </summary>
public string ProfileDirectory { get; set; }

/// <summary>
/// Gets or sets the additional capabilities.
/// </summary>
public Dictionary<string, object> AdditionalCapabilities { get; set; }

/// <inheritdoc/>
public object Clone()
{
Expand All @@ -32,6 +51,8 @@ public override ChromeOptions ToChrome()
options.AddArgument($"--user-data-dir={this.ProfileDirectory}");
}

this.AddAdditionalCapabilities(options);

return options;
}

Expand All @@ -46,7 +67,37 @@ public override FirefoxOptions ToFireFox()
options.AddArgument($"-profile \"{this.ProfileDirectory}\"");
}

this.AddAdditionalCapabilities(options);

return options;
}

/// <inheritdoc/>
public override EdgeOptions ToEdge()
{
var options = base.ToEdge();

this.AddAdditionalCapabilities(options);

return options;
}

/// <inheritdoc/>
public override InternetExplorerOptions ToInternetExplorer()
{
var options = base.ToInternetExplorer();

this.AddAdditionalCapabilities(options);

return options;
}

private void AddAdditionalCapabilities(DriverOptions options)
{
foreach (var desiredCapability in this.AdditionalCapabilities)
{
options.AddGlobalCapability(desiredCapability.Key, desiredCapability.Value);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Capgemini.PowerApps.SpecFlowBindings.Extensions
{
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;

/// <summary>
/// Extensions to the <see cref="DriverOptions"/> class.
/// </summary>
public static class DriverOptionsExtensions
{
/// <summary>
/// Adds a global capability to driver options.
/// </summary>
/// <param name="options">The driver options.</param>
/// <param name="name">The name of the capability.</param>
/// <param name="value">The value of the capability.</param>
internal static void AddGlobalCapability(this DriverOptions options, string name, object value)
{
switch (options)
{
case ChromeOptions chromeOptions:
chromeOptions.AddAdditionalCapability(name, value, true);
break;
case FirefoxOptions firefoxOptions:
firefoxOptions.AddAdditionalCapability(name, value, true);
break;
case InternetExplorerOptions internetExplorerOptions:
internetExplorerOptions.AddAdditionalCapability(name, value, true);
break;
default:
options.AddAdditionalCapability(name, value);
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ browserOptions:
height: 1080
startMaximized: false
driversPath: ChromeWebDriver
additionalCapabilities:
capabilityName: capabilityVaue
applicationUser:
tenantId: POWERAPPS_SPECFLOW_BINDINGS_TEST_TENANTID
clientId: POWERAPPS_SPECFLOW_BINDINGS_TEST_CLIENTID
Expand Down

0 comments on commit 4ce4d28

Please sign in to comment.