Skip to content

Commit 4ce4d28

Browse files
authored
feat: additional capabilities (#131)
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.
1 parent dcc353e commit 4ce4d28

File tree

4 files changed

+94
-1
lines changed

4 files changed

+94
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ browserOptions: # optional - will use default EasyRepro options if not set
6363
height: 1080
6464
startMaximized: false
6565
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)
66+
additionalCapabilities: # optional - additional capabilities to pass to the WebDriver
67+
capabilityName: capabilityValue
6668
applicationUser: # optional - populate if creating test data for users other than the current user
6769
tenantId: SPECFLOW_POWERAPPS_TENANTID optional # mandatory
6870
clientId: SPECFLOW_POWERAPPS_CLIENTID # mandatory

bindings/src/Capgemini.PowerApps.SpecFlowBindings/Configuration/BrowserOptionsWithProfileSupport.cs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
namespace Capgemini.PowerApps.SpecFlowBindings.Configuration
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.IO;
6+
using Capgemini.PowerApps.SpecFlowBindings.Extensions;
57
using Microsoft.Dynamics365.UIAutomation.Browser;
8+
using OpenQA.Selenium;
69
using OpenQA.Selenium.Chrome;
10+
using OpenQA.Selenium.Edge;
711
using OpenQA.Selenium.Firefox;
12+
using OpenQA.Selenium.IE;
813

914
/// <summary>
10-
/// Extends the EasyRepro <see cref="BrowserOptions"/> class with additonal support for chrome profiles.
15+
/// Extends the EasyRepro <see cref="BrowserOptions"/> class with support for additional configuration.
1116
/// </summary>
1217
public class BrowserOptionsWithProfileSupport : BrowserOptions, ICloneable
1318
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="BrowserOptionsWithProfileSupport"/> class.
21+
/// </summary>
22+
public BrowserOptionsWithProfileSupport()
23+
: base()
24+
{
25+
this.AdditionalCapabilities = new Dictionary<string, object>();
26+
}
27+
1428
/// <summary>
1529
/// Gets or sets the directory to use as the user profile.
1630
/// </summary>
1731
public string ProfileDirectory { get; set; }
1832

33+
/// <summary>
34+
/// Gets or sets the additional capabilities.
35+
/// </summary>
36+
public Dictionary<string, object> AdditionalCapabilities { get; set; }
37+
1938
/// <inheritdoc/>
2039
public object Clone()
2140
{
@@ -32,6 +51,8 @@ public override ChromeOptions ToChrome()
3251
options.AddArgument($"--user-data-dir={this.ProfileDirectory}");
3352
}
3453

54+
this.AddAdditionalCapabilities(options);
55+
3556
return options;
3657
}
3758

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

70+
this.AddAdditionalCapabilities(options);
71+
4972
return options;
5073
}
74+
75+
/// <inheritdoc/>
76+
public override EdgeOptions ToEdge()
77+
{
78+
var options = base.ToEdge();
79+
80+
this.AddAdditionalCapabilities(options);
81+
82+
return options;
83+
}
84+
85+
/// <inheritdoc/>
86+
public override InternetExplorerOptions ToInternetExplorer()
87+
{
88+
var options = base.ToInternetExplorer();
89+
90+
this.AddAdditionalCapabilities(options);
91+
92+
return options;
93+
}
94+
95+
private void AddAdditionalCapabilities(DriverOptions options)
96+
{
97+
foreach (var desiredCapability in this.AdditionalCapabilities)
98+
{
99+
options.AddGlobalCapability(desiredCapability.Key, desiredCapability.Value);
100+
}
101+
}
51102
}
52103
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace Capgemini.PowerApps.SpecFlowBindings.Extensions
2+
{
3+
using OpenQA.Selenium;
4+
using OpenQA.Selenium.Chrome;
5+
using OpenQA.Selenium.Firefox;
6+
using OpenQA.Selenium.IE;
7+
8+
/// <summary>
9+
/// Extensions to the <see cref="DriverOptions"/> class.
10+
/// </summary>
11+
public static class DriverOptionsExtensions
12+
{
13+
/// <summary>
14+
/// Adds a global capability to driver options.
15+
/// </summary>
16+
/// <param name="options">The driver options.</param>
17+
/// <param name="name">The name of the capability.</param>
18+
/// <param name="value">The value of the capability.</param>
19+
internal static void AddGlobalCapability(this DriverOptions options, string name, object value)
20+
{
21+
switch (options)
22+
{
23+
case ChromeOptions chromeOptions:
24+
chromeOptions.AddAdditionalCapability(name, value, true);
25+
break;
26+
case FirefoxOptions firefoxOptions:
27+
firefoxOptions.AddAdditionalCapability(name, value, true);
28+
break;
29+
case InternetExplorerOptions internetExplorerOptions:
30+
internetExplorerOptions.AddAdditionalCapability(name, value, true);
31+
break;
32+
default:
33+
options.AddAdditionalCapability(name, value);
34+
break;
35+
}
36+
}
37+
}
38+
}

bindings/tests/Capgemini.PowerApps.SpecFlowBindings.UiTests/power-apps-bindings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ browserOptions:
77
height: 1080
88
startMaximized: false
99
driversPath: ChromeWebDriver
10+
additionalCapabilities:
11+
capabilityName: capabilityVaue
1012
applicationUser:
1113
tenantId: POWERAPPS_SPECFLOW_BINDINGS_TEST_TENANTID
1214
clientId: POWERAPPS_SPECFLOW_BINDINGS_TEST_CLIENTID

0 commit comments

Comments
 (0)