Skip to content

Commit 4239df4

Browse files
committed
Refactor capabilities handling and update tests
- Set `BrowserName` to "Uia" in `UiaOptions` constructor. - Replace test method with `NewApplicationDriverTest` in `UiaDriverTests`. - Modify `PublicExtensions` to use `firstMatch` dictionary in `NewSessionModel`. - Remove `FirstMatch` property from `CapabilitiesModel`. - Update `SessionModel` to add `FirstMatch` property and remove `DesiredCapabilities` and `Build` method.
1 parent 9db3376 commit 4239df4

File tree

5 files changed

+8
-99
lines changed

5 files changed

+8
-99
lines changed

src/G4.WebDriver.Remote.Uia/UiaOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class UiaOptions : WebDriverOptionsBase
1717
public UiaOptions()
1818
{
1919
UiaOptionsDictionary = [];
20+
BrowserName = "Uia";
2021
}
2122
#endregion
2223

src/G4.WebDriver.Tests/UiaDriverTests.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,6 @@ namespace G4.WebDriver.Tests
1313
[TestCategory("WindowsAppTest")]
1414
public class UiaDriverTests : TestBase<UiaDriver>
1515
{
16-
[TestMethod]
17-
public void Test()
18-
{
19-
var options = new UiaOptions
20-
{
21-
App = "notepad.exe"
22-
};
23-
var driver = new UiaDriver(new Uri("http://localhost:5555/wd/hub"), options);
24-
var element = driver.FindElement(By.Xpath("//Document[@Name='Text editor']"));
25-
var attribute = element.GetAttribute("Name");
26-
27-
((UiaElement)element).MoveToElement();
28-
((UiaElement)element).MoveToElement(new MousePositionInputModel
29-
{
30-
Alignment = "TopLeft",
31-
OffsetX = 100,
32-
OffsetY = 100,
33-
34-
});
35-
((UiaElement)element).MoveToElement(new MousePositionInputModel
36-
{
37-
Alignment = "TopRight",
38-
OffsetX = 100,
39-
OffsetY = 100,
40-
41-
});
42-
43-
element = driver.FindElement(By.Xpath("//Window[@PartialName='Notepad']//MenuItem[@Name='File']"));
44-
((UiaElement)element).SendClick();
45-
46-
var b = "";
47-
}
48-
4916
[TestMethod(displayName: "Verify that a new application driver can be instantiated and perform UI interactions correctly.")]
5017
public void NewApplicationDriverTest()
5118
{

src/G4.WebDriver/Extensions/PublicExtensions.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -845,44 +845,20 @@ public static SessionModel NewSessionModel(this CapabilitiesModel model)
845845
{
846846
// Initialize the desired capabilities dictionary.
847847
var desired = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
848+
var firstMatch = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
848849

849850
// Populate the desired capabilities from AlwaysMatch.
850851
foreach (var capability in model.AlwaysMatch)
851852
{
852853
desired[capability.Key] = capability.Value;
853-
}
854-
855-
// Populate the desired capabilities from FirstMatch.
856-
foreach (var capabilities in model.FirstMatch)
857-
{
858-
foreach (var capability in capabilities)
859-
{
860-
desired[capability.Key] = capability.Value;
861-
}
862-
}
863-
864-
// If FirstMatch is empty, move the 'browserName' entry to FirstMatch.
865-
if (model.FirstMatch?.Any() == false)
866-
{
867-
const string BrowserName = "browserName";
868-
_ = desired.TryGetValue(BrowserName, out object browserNameOut);
869-
870-
// Create a new entry for FirstMatch.
871-
var entry = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
872-
{
873-
[BrowserName] = $"{browserNameOut}"
874-
};
875-
876-
// Add the entry to FirstMatch and remove it from AlwaysMatch.
877-
model.FirstMatch = model.FirstMatch.Concat([entry]);
878-
model.AlwaysMatch.Remove(BrowserName);
854+
firstMatch[capability.Key] = capability.Value;
879855
}
880856

881857
// Return a new SessionModel instance.
882858
return new SessionModel
883859
{
884860
Capabilities = model,
885-
DesiredCapabilities = desired
861+
FirstMatch = [firstMatch]
886862
};
887863
}
888864

src/G4.WebDriver/Models/CapabilitiesModel.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class CapabilitiesModel
1616
public CapabilitiesModel()
1717
{
1818
AlwaysMatch = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
19-
FirstMatch = [];
2019
}
2120
#endregion
2221

@@ -25,11 +24,6 @@ public CapabilitiesModel()
2524
/// Gets or sets a collection of capabilities that must all be matched.
2625
/// </summary>
2726
public IDictionary<string, object> AlwaysMatch { get; set; }
28-
29-
/// <summary>
30-
/// Gets or sets a collection of capabilities that at least one must be matched.
31-
/// </summary>
32-
public IEnumerable<IDictionary<string, object>> FirstMatch { get; set; }
3327
#endregion
3428
}
3529
}

src/G4.WebDriver/Models/SessionModel.cs

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public SessionModel()
2121
// Initialize the Capabilities model.
2222
Capabilities = new CapabilitiesModel();
2323

24-
// Initialize the DesiredCapabilities dictionary with case-insensitive string keys.
25-
DesiredCapabilities = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
24+
// Initialize the FirstMatch dictionary with case-insensitive string keys.
25+
FirstMatch = [];
2626

2727
// Set the StartNewSession flag to true by default.
2828
StartNewSession = true;
@@ -36,10 +36,9 @@ public SessionModel()
3636
public CapabilitiesModel Capabilities { get; set; }
3737

3838
/// <summary>
39-
/// Gets or sets the desired capabilities that specify the desired features for the WebDriver session.
40-
/// These capabilities define what the WebDriver session should support.
39+
/// Gets or sets a collection of capabilities that at least one must be matched.
4140
/// </summary>
42-
public IDictionary<string, object> DesiredCapabilities { get; set; }
41+
public IEnumerable<IDictionary<string, object>> FirstMatch { get; set; }
4342

4443
/// <summary>
4544
/// Gets or sets the password needed for intermediary node authentication.
@@ -60,33 +59,5 @@ public SessionModel()
6059
/// </summary>
6160
public string User { get; set; }
6261
#endregion
63-
64-
#region *** Methods ***
65-
/// <summary>
66-
/// Builds the session model by merging the capabilities into the desired capabilities.
67-
/// Merges both FirstMatch and AlwaysMatch capabilities into the DesiredCapabilities dictionary.
68-
/// </summary>
69-
/// <returns>Returns the current <see cref="SessionModel"/> instance with updated desired capabilities.</returns>
70-
public SessionModel Build()
71-
{
72-
// Merge capabilities from the FirstMatch list into DesiredCapabilities.
73-
for (int i = 0; i < Capabilities.FirstMatch.Count(); i++)
74-
{
75-
foreach (var item in Capabilities.FirstMatch.ElementAt(i))
76-
{
77-
DesiredCapabilities[item.Key] = item.Value;
78-
}
79-
}
80-
81-
// Merge capabilities from the AlwaysMatch dictionary into DesiredCapabilities.
82-
foreach (var item in Capabilities.AlwaysMatch)
83-
{
84-
DesiredCapabilities[item.Key] = item.Value;
85-
}
86-
87-
// Return the updated session model instance.
88-
return this;
89-
}
90-
#endregion
9162
}
9263
}

0 commit comments

Comments
 (0)