Skip to content

Commit 02ad8d0

Browse files
committed
Go back to dictionary style
1 parent 312eab7 commit 02ad8d0

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

dotnet/src/webdriver/DriverFinder.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// </copyright>
1919

2020
using System;
21+
using System.Collections.Generic;
2122
using System.Diagnostics.CodeAnalysis;
2223
using System.Globalization;
2324
using System.IO;
@@ -34,7 +35,7 @@ namespace OpenQA.Selenium
3435
public class DriverFinder
3536
{
3637
private readonly DriverOptions options;
37-
private SeleniumManagerPaths? paths;
38+
private Dictionary<string, string>? paths;
3839
private const string BrowserPathKey = "browser_path";
3940
private const string DriverPathKey = "driver_path";
4041

@@ -55,7 +56,7 @@ public DriverFinder(DriverOptions options)
5556
/// </returns>
5657
public string GetBrowserPath()
5758
{
58-
return BinaryPaths().BrowserPath;
59+
return BinaryPaths()[SeleniumManager.BrowserPath];
5960
}
6061

6162
/// <summary>
@@ -66,7 +67,7 @@ public string GetBrowserPath()
6667
/// </returns>
6768
public string GetDriverPath()
6869
{
69-
return BinaryPaths().DriverPath;
70+
return BinaryPaths()[SeleniumManager.DriverPath];
7071
}
7172

7273
/// <summary>
@@ -103,16 +104,16 @@ public bool TryGetBrowserPath([NotNullWhen(true)] out string? browserPath)
103104
/// A Dictionary with the validated browser and driver path.
104105
/// </returns>
105106
/// <exception cref="NoSuchDriverException">If one of the paths does not exist.</exception>
106-
private SeleniumManagerPaths BinaryPaths()
107+
private Dictionary<string, string> BinaryPaths()
107108
{
108-
if (paths is not null && !string.IsNullOrWhiteSpace(paths.DriverPath))
109+
if (paths is not null && !string.IsNullOrWhiteSpace(paths[SeleniumManager.DriverPath]))
109110
{
110111
return paths;
111112
}
112113

113-
SeleniumManagerPaths binaryPaths = SeleniumManager.BinaryPaths(CreateArguments());
114-
string driverPath = binaryPaths.DriverPath;
115-
string browserPath = binaryPaths.BrowserPath;
114+
Dictionary<string, string> binaryPaths = SeleniumManager.BinaryPaths(CreateArguments());
115+
string driverPath = binaryPaths[SeleniumManager.DriverPath];
116+
string browserPath = binaryPaths[SeleniumManager.BrowserPath];
116117

117118
if (File.Exists(driverPath))
118119
{

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ namespace OpenQA.Selenium
3838
/// </summary>
3939
public static class SeleniumManager
4040
{
41+
internal const string DriverPath = "driver_path";
42+
internal const string BrowserPath = "browser_path";
43+
4144
private static readonly ILogger _logger = Log.GetLogger(typeof(SeleniumManager));
4245

4346
private static readonly Lazy<string> _lazyBinaryFullPath = new(() =>
@@ -80,7 +83,7 @@ public static class SeleniumManager
8083
/// <returns>
8184
/// An array with two entries, one for the driver path, and another one for the browser path.
8285
/// </returns>
83-
public static SeleniumManagerPaths BinaryPaths(string arguments)
86+
public static Dictionary<string, string> BinaryPaths(string arguments)
8487
{
8588
StringBuilder argsBuilder = new StringBuilder(arguments);
8689
argsBuilder.Append(" --language-binding csharp");
@@ -90,12 +93,17 @@ public static SeleniumManagerPaths BinaryPaths(string arguments)
9093
argsBuilder.Append(" --debug");
9194
}
9295

93-
var binaryPaths = RunCommand(_lazyBinaryFullPath.Value, argsBuilder.ToString());
96+
var smCommandResult = RunCommand(_lazyBinaryFullPath.Value, argsBuilder.ToString());
97+
Dictionary<string, string> binaryPaths = new()
98+
{
99+
{ BrowserPath, smCommandResult.BrowserPath },
100+
{ DriverPath, smCommandResult.DriverPath }
101+
};
94102

95103
if (_logger.IsEnabled(LogEventLevel.Trace))
96104
{
97-
_logger.Trace($"Driver path: {binaryPaths.DriverPath}");
98-
_logger.Trace($"Browser path: {binaryPaths.BrowserPath}");
105+
_logger.Trace($"Driver path: {binaryPaths[DriverPath]}");
106+
_logger.Trace($"Browser path: {binaryPaths[BrowserPath]}");
99107
}
100108

101109
return binaryPaths;
@@ -109,7 +117,7 @@ public static SeleniumManagerPaths BinaryPaths(string arguments)
109117
/// <returns>
110118
/// the standard output of the execution.
111119
/// </returns>
112-
private static SeleniumManagerPaths RunCommand(string fileName, string arguments)
120+
private static ResultResponse RunCommand(string fileName, string arguments)
113121
{
114122
Process process = new Process();
115123
process.StartInfo.FileName = _lazyBinaryFullPath.Value;
@@ -203,23 +211,19 @@ private static SeleniumManagerPaths RunCommand(string fileName, string arguments
203211
}
204212
}
205213

206-
internal sealed record SeleniumManagerResponse(IReadOnlyList<LogEntryResponse> Logs, SeleniumManagerPaths Result)
214+
internal sealed record SeleniumManagerResponse(IReadOnlyList<LogEntryResponse> Logs, ResultResponse Result)
207215
{
208216
public sealed record LogEntryResponse(string Level, string Message);
209-
}
210217

211-
/// <summary>
212-
/// Response from Selenium Manager about the paths and their locations.
213-
/// </summary>
214-
/// <param name="DriverPath">The path to the driver binary.</param>
215-
/// <param name="BrowserPath">The path to the browser binary, or <see cref="string.Empty"/> if none exists.</param>
216-
public sealed record SeleniumManagerPaths
217-
(
218-
[property: JsonPropertyName("driver_path")]
218+
internal sealed record ResultResponse
219+
(
220+
[property: JsonPropertyName("driver_path")]
219221
string DriverPath,
220-
[property: JsonPropertyName("browser_path")]
222+
[property: JsonPropertyName("browser_path")]
221223
string BrowserPath
222-
);
224+
);
225+
}
226+
223227

224228
[JsonSerializable(typeof(SeleniumManagerResponse))]
225229
[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)]

0 commit comments

Comments
 (0)