Skip to content

Commit 93692f7

Browse files
committed
Refactor WebDriver capabilities and add ClientApp project
Updated DriverFactory.cs to use firstMatch instead of desiredCapabilities. Modified DriverPluginBase.cs to initialize and merge firstMatch capabilities directly into userSession. Removed desiredCapabilities handling in LocalExtensions.cs, focusing on alwaysMatch capabilities. Updated G4.Abstraction.WebDriver.csproj to reference newer package versions. Added ClientApp project to G4.Abstraction.sln with build settings for Debug and Release. Created ClientApp.csproj targeting .NET 8.0, referencing other solution projects. Added Program.cs to demonstrate WebDriver instance creation using DriverFactory.
1 parent a764a1e commit 93692f7

File tree

7 files changed

+98
-34
lines changed

7 files changed

+98
-34
lines changed

src/ClientApp/ClientApp.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\G4.Abstraction.Cli\G4.Abstraction.Cli.csproj" />
12+
<ProjectReference Include="..\G4.Abstraction.Logging\G4.Abstraction.Logging.csproj" />
13+
<ProjectReference Include="..\G4.Abstraction.WebDriver\G4.Abstraction.WebDriver.csproj" />
14+
</ItemGroup>
15+
16+
</Project>

src/ClientApp/Program.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using G4.Abstraction.WebDriver;
2+
3+
var driverParameters = new Dictionary<string, object>
4+
{
5+
["driverBinaries"] = "http://localhost/wd/hub",
6+
["driver"] = "UiaDriver",
7+
["capabilities"] = new Dictionary<string, object>
8+
{
9+
["alwaysMatch"] = new Dictionary<string, object>
10+
{
11+
["browserName"] = "Uia",
12+
["uia:options"] = new Dictionary<string, object>
13+
{
14+
["app"] = "notepad.exe"
15+
}
16+
}
17+
},
18+
["firstMatch"] = new List<Dictionary<string, object>>
19+
{
20+
new()
21+
{
22+
["label"] = "UIA"
23+
}
24+
}
25+
};
26+
27+
var driver = new DriverFactory(driverParameters).NewDriver();
28+
29+
driver.Dispose();
30+
31+
driverParameters = new Dictionary<string, object>
32+
{
33+
["driverBinaries"] = "http://localhost/wd/hub",
34+
["driver"] = "MicrosoftEdgeDriver"
35+
};
36+
37+
driver = new DriverFactory(driverParameters).NewDriver();
38+
driver.Dispose();
39+
40+
driverParameters = new Dictionary<string, object>
41+
{
42+
["driverBinaries"] = "http://localhost/wd/hub",
43+
["driver"] = "ChromeDriver"
44+
};
45+
46+
driver = new DriverFactory(driverParameters).NewDriver();
47+
driver.Dispose();
48+
49+
driverParameters = new Dictionary<string, object>
50+
{
51+
["driverBinaries"] = "http://localhost/wd/hub",
52+
["driver"] = "Firefox"
53+
};
54+
55+
driver = new DriverFactory(driverParameters).NewDriver();
56+
driver.Dispose();

src/G4.Abstraction.WebDriver/DriverFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public DriverFactory(IDictionary<string, object> driverParams)
8888

8989
// Set capabilities using provided values or default to empty models
9090
var capabilities = driverParams.Find("capabilities", new CapabilitiesModel());
91-
var desiredCapabilities = driverParams.Find("desiredCapabilities", NewDictionary());
91+
var desiredCapabilities = driverParams.Find("firstMatch", Enumerable.Empty<IDictionary<string, object>>());
9292

9393
// Create and assign a new session model
9494
_sessionModel = new SessionModel
9595
{
9696
Capabilities = capabilities,
97-
DesiredCapabilities = desiredCapabilities,
97+
FirstMatch = desiredCapabilities,
9898
};
9999
}
100100
#endregion

src/G4.Abstraction.WebDriver/DriverPluginBase.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static IWebDriver NewLocalDriver<TDriver, TService, TOption>(string binar
3232
var options = new TOption();
3333

3434
// Build the user session using specified options and session model.
35-
var userSession = NewSessionModel(options, session).Build();
35+
var userSession = NewSessionModel(options, session);
3636

3737
// Instantiate a new WebDriver service.
3838
var service = Activator.CreateInstance(typeof(TService), binariesPath);
@@ -99,7 +99,7 @@ public static IWebDriver NewRemoteDriver<TOption>(string binariesPath, SessionMo
9999
var options = new TOption();
100100

101101
// Build the user session using specified options and session model.
102-
var userSession = NewSessionModel(options, session).Build();
102+
var userSession = NewSessionModel(options, session);
103103

104104
// Instantiate a new WebDriverCommandInvoker.
105105
var invoker = new WebDriverCommandInvoker(new Uri(binariesPath), timeout);
@@ -124,7 +124,7 @@ public static IWebDriver NewRemoteDriver<TDriver, TOption>(string binariesPath,
124124
var options = new TOption();
125125

126126
// Build the user session using specified options and session model.
127-
var userSession = NewSessionModel(options, session).Build();
127+
var userSession = NewSessionModel(options, session);
128128

129129
// Instantiate a new WebDriverCommandInvoker.
130130
var invoker = new WebDriverCommandInvoker(new Uri(binariesPath), timeout);
@@ -182,23 +182,16 @@ private static SessionModel NewSessionModel(WebDriverOptionsBase options, Sessio
182182
userSession.Capabilities.AlwaysMatch[item.Key] = item.Value;
183183
}
184184

185-
// Transfer desired capabilities from the session to the user session.
186-
foreach (var item in session.DesiredCapabilities)
187-
{
188-
userSession.DesiredCapabilities[item.Key] = item.Value;
189-
}
190-
191185
// Initialize the FirstMatch of the session.
192-
session.Capabilities.FirstMatch ??= [];
186+
session.FirstMatch ??= [];
193187

194188
// Initialize the FirstMatch capabilities in the user session.
195-
userSession.Capabilities.FirstMatch ??= [];
189+
userSession.FirstMatch ??= [];
196190

197191
// Merge the FirstMatch capabilities from the session into the user session.
198-
userSession.Capabilities.FirstMatch = userSession
199-
.Capabilities
192+
userSession.FirstMatch = userSession
200193
.FirstMatch
201-
.Concat(session.Capabilities.FirstMatch)
194+
.Concat(session.FirstMatch)
202195
.Where(i => i.Keys.Count > 0);
203196

204197
// Return the created user session.

src/G4.Abstraction.WebDriver/Extensions/LocalExtensions.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ public static T ConvertToObject<T>(this IDictionary<string, object> dictionary)
8282
.GetProperties(Flags)
8383
.Where(i => i.SetMethod != null);
8484

85-
// Set properties based on desired capabilities
86-
foreach (var item in model.DesiredCapabilities)
87-
{
88-
var property = targetProperties.FirstOrDefault(i => i.Name.Equals(item.Key, Compare));
89-
property?.SetValue(instance, item.Value);
90-
}
91-
9285
// Set properties based on capabilities always matching
9386
foreach (var item in model.Capabilities.AlwaysMatch)
9487
{

src/G4.Abstraction.WebDriver/G4.Abstraction.WebDriver.csproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
</ItemGroup>
3131

3232
<ItemGroup>
33-
<PackageReference Include="G4.Cache" Version="2025.2.5.27" />
34-
<PackageReference Include="G4.WebDriver" Version="2025.2.6.8" />
35-
<PackageReference Include="G4.WebDriver.Remote.Android" Version="2025.2.6.8" />
36-
<PackageReference Include="G4.WebDriver.Remote.Appium" Version="2025.2.6.8" />
37-
<PackageReference Include="G4.WebDriver.Remote.Chrome" Version="2025.2.6.8" />
38-
<PackageReference Include="G4.WebDriver.Remote.Chromium" Version="2025.2.6.8" />
39-
<PackageReference Include="G4.WebDriver.Remote.Edge" Version="2025.2.6.8" />
40-
<PackageReference Include="G4.WebDriver.Remote.Firefox" Version="2025.2.6.8" />
41-
<PackageReference Include="G4.WebDriver.Remote.Opera" Version="2025.2.6.8" />
42-
<PackageReference Include="G4.WebDriver.Remote.Uia" Version="2025.2.6.8" />
43-
<PackageReference Include="G4.WebDriver.Simulator" Version="2025.2.6.8" />
33+
<PackageReference Include="G4.Cache" Version="2025.2.6.28" />
34+
<PackageReference Include="G4.WebDriver" Version="2025.2.7.9" />
35+
<PackageReference Include="G4.WebDriver.Remote.Android" Version="2025.2.7.9" />
36+
<PackageReference Include="G4.WebDriver.Remote.Appium" Version="2025.2.7.9" />
37+
<PackageReference Include="G4.WebDriver.Remote.Chrome" Version="2025.2.7.9" />
38+
<PackageReference Include="G4.WebDriver.Remote.Chromium" Version="2025.2.7.9" />
39+
<PackageReference Include="G4.WebDriver.Remote.Edge" Version="2025.2.7.9" />
40+
<PackageReference Include="G4.WebDriver.Remote.Firefox" Version="2025.2.7.9" />
41+
<PackageReference Include="G4.WebDriver.Remote.Opera" Version="2025.2.7.9" />
42+
<PackageReference Include="G4.WebDriver.Remote.Uia" Version="2025.2.7.9" />
43+
<PackageReference Include="G4.WebDriver.Simulator" Version="2025.2.7.9" />
4444
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
4545
</ItemGroup>
4646

src/G4.Abstraction.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{0485
2828
..\.github\workflows\release-pipline.yml = ..\.github\workflows\release-pipline.yml
2929
EndProjectSection
3030
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientApp", "ClientApp\ClientApp.csproj", "{0B97D54A-1903-4A8E-BAAA-8B157BAD652D}"
32+
EndProject
3133
Global
3234
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3335
Debug|Any CPU = Debug|Any CPU
@@ -46,6 +48,10 @@ Global
4648
{D6741F25-B33A-4CC3-8688-A9FB8B00931A}.Debug|Any CPU.Build.0 = Debug|Any CPU
4749
{D6741F25-B33A-4CC3-8688-A9FB8B00931A}.Release|Any CPU.ActiveCfg = Release|Any CPU
4850
{D6741F25-B33A-4CC3-8688-A9FB8B00931A}.Release|Any CPU.Build.0 = Release|Any CPU
51+
{0B97D54A-1903-4A8E-BAAA-8B157BAD652D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
52+
{0B97D54A-1903-4A8E-BAAA-8B157BAD652D}.Debug|Any CPU.Build.0 = Debug|Any CPU
53+
{0B97D54A-1903-4A8E-BAAA-8B157BAD652D}.Release|Any CPU.ActiveCfg = Release|Any CPU
54+
{0B97D54A-1903-4A8E-BAAA-8B157BAD652D}.Release|Any CPU.Build.0 = Release|Any CPU
4955
EndGlobalSection
5056
GlobalSection(SolutionProperties) = preSolution
5157
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)