Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3dd4bd1
Better api to discover browser path
nvborisenko Jan 29, 2026
889ed9c
Remove old api
nvborisenko Jan 29, 2026
71dd903
Debug or Trace if enabled
nvborisenko Jan 29, 2026
9eb26b9
Introduce mixed logs
nvborisenko Jan 29, 2026
ee625a9
Timeout
nvborisenko Jan 29, 2026
936d220
Format error output in exception
nvborisenko Jan 29, 2026
2d17591
Parse SM io messages
nvborisenko Jan 29, 2026
628e287
Parse error level
nvborisenko Jan 29, 2026
a3bf877
Remove duplicate log level handling for warnings
nvborisenko Jan 29, 2026
156f2b6
Docs for options
nvborisenko Jan 29, 2026
dd09060
Don't expose magic const
nvborisenko Jan 29, 2026
6f8df55
Compiled regex
nvborisenko Jan 29, 2026
0301772
Remove log enabled check
nvborisenko Jan 29, 2026
f271e2b
Local datetime
nvborisenko Jan 29, 2026
2ccbd77
Dispose process object
nvborisenko Jan 29, 2026
68c257a
Reveal STDOUT if sm exited with error
nvborisenko Jan 29, 2026
7b4dee3
Apply suggestion around regex
nvborisenko Jan 30, 2026
f6b3470
Merge branch 'trunk' into sm-output-stream
nvborisenko Jan 31, 2026
3a28848
Use log-level switch
nvborisenko Feb 1, 2026
75fe941
WARN log level
nvborisenko Feb 1, 2026
b531bd3
Root check for nullable options
nvborisenko Feb 1, 2026
175d609
Update dotnet/src/webdriver/DriverFinder.cs
nvborisenko Feb 1, 2026
480994e
Correct spacing in #if preprocessor directive
nvborisenko Feb 3, 2026
5ea94c9
Make cached driver path local nullable
nvborisenko Feb 3, 2026
45e28d7
Merge branch 'trunk' into sm-output-stream
nvborisenko Feb 3, 2026
83c28ca
Parse log timestamps with invariant culture and UTC
nvborisenko Feb 3, 2026
1e392e8
Rename discovery types to BrowserDiscovery*
nvborisenko Feb 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 22 additions & 47 deletions dotnet/src/webdriver/DriverFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ namespace OpenQA.Selenium;
/// </summary>
public class DriverFinder
{
internal const string DriverPathKey = "driver_path";
internal const string BrowserPathKey = "browser_path";

private readonly DriverOptions options;
private readonly Dictionary<string, string> paths = new Dictionary<string, string>();

Expand All @@ -52,7 +55,7 @@ public DriverFinder(DriverOptions options)
/// </returns>
public string GetBrowserPath()
{
return BinaryPaths()[SeleniumManager.BrowserPathKey];
return BinaryPaths()[BrowserPathKey];
}

/// <summary>
Expand All @@ -63,7 +66,7 @@ public string GetBrowserPath()
/// </returns>
public string GetDriverPath()
{
return BinaryPaths()[SeleniumManager.DriverPathKey];
return BinaryPaths()[DriverPathKey];
}

/// <summary>
Expand Down Expand Up @@ -102,18 +105,29 @@ public bool TryGetBrowserPath([NotNullWhen(true)] out string? browserPath)
/// <exception cref="NoSuchDriverException">If one of the paths does not exist.</exception>
private Dictionary<string, string> BinaryPaths()
{
if (paths.ContainsKey(SeleniumManager.DriverPathKey) && !string.IsNullOrWhiteSpace(paths[SeleniumManager.DriverPathKey]))
if (paths.TryGetValue(DriverPathKey, out string? cachedDriverPath) && !string.IsNullOrWhiteSpace(cachedDriverPath))
{
return paths;
}

Dictionary<string, string> binaryPaths = SeleniumManager.BinaryPaths(CreateArguments());
string driverPath = binaryPaths[SeleniumManager.DriverPathKey];
string browserPath = binaryPaths[SeleniumManager.BrowserPathKey];
if (options.BrowserName is null)
{
throw new NoSuchDriverException("Browser name must be specified to find the driver using Selenium Manager.");
}

BrowserDiscoveryResult smResult = SeleniumManager.DiscoverBrowser(options.BrowserName, new BrowserDiscoveryOptions
{
BrowserVersion = options.BrowserVersion,
BrowserPath = options.BinaryLocation,
Proxy = options.Proxy?.SslProxy ?? options.Proxy?.HttpProxy
});

string driverPath = smResult.DriverPath;
string browserPath = smResult.BrowserPath;

if (File.Exists(driverPath))
{
paths.Add(SeleniumManager.DriverPathKey, driverPath);
paths.Add(DriverPathKey, driverPath);
}
else
{
Expand All @@ -122,7 +136,7 @@ private Dictionary<string, string> BinaryPaths()

if (File.Exists(browserPath))
{
paths.Add(SeleniumManager.BrowserPathKey, browserPath);
paths.Add(BrowserPathKey, browserPath);
}
else
{
Expand All @@ -131,43 +145,4 @@ private Dictionary<string, string> BinaryPaths()

return paths;
}

/// <summary>
/// Create arguments to invoke Selenium Manager
/// </summary>
/// <returns>
/// A string with all arguments to invoke Selenium Manager
/// </returns>
/// <exception cref="NoSuchDriverException"></exception>
private string CreateArguments()
{
StringBuilder argsBuilder = new StringBuilder();
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --browser \"{0}\"", options.BrowserName);

if (!string.IsNullOrEmpty(options.BrowserVersion))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --browser-version {0}", options.BrowserVersion);
}

string? browserBinary = options.BinaryLocation;
if (!string.IsNullOrEmpty(browserBinary))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --browser-path \"{0}\"", browserBinary);
}

if (options.Proxy != null)
{
if (options.Proxy.SslProxy != null)
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --proxy \"{0}\"", options.Proxy.SslProxy);
}
else if (options.Proxy.HttpProxy != null)
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --proxy \"{0}\"", options.Proxy.HttpProxy);
}
}

return argsBuilder.ToString();
}

}
3 changes: 2 additions & 1 deletion dotnet/src/webdriver/Internal/Logging/ILogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ public interface ILogContext : IDisposable
/// Emits a log message using the specified logger, log level, and message.
/// </summary>
/// <param name="logger">The logger to emit the log message.</param>
/// <param name="timestamp">The timestamp of the log event.</param>
/// <param name="level">The log level of the message.</param>
/// <param name="message">The log message.</param>
internal void EmitMessage(ILogger logger, LogEventLevel level, string message);
internal void EmitMessage(ILogger logger, DateTimeOffset timestamp, LogEventLevel level, string message);

/// <summary>
/// Sets the minimum log level for the current context.
Expand Down
8 changes: 8 additions & 0 deletions dotnet/src/webdriver/Internal/Logging/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ internal interface ILogger
/// <param name="message">The log message.</param>
void Error(string message);

/// <summary>
/// Writes a log message with a specific timestamp and log level.
/// </summary>
/// <param name="timestamp">The timestamp of the log event.</param>
/// <param name="level">The severity level of the log message.</param>
/// <param name="message">The log message.</param>
void LogMessage(DateTimeOffset timestamp, LogEventLevel level, string message);

/// <summary>
/// Gets or sets the log event level.
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions dotnet/src/webdriver/Internal/Logging/LogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ public bool IsEnabled(ILogger logger, LogEventLevel level)
return Handlers != null && level >= _level && (_loggers?.TryGetValue(logger.Issuer, out var loggerEntry) != true || level >= loggerEntry?.Level);
}

public void EmitMessage(ILogger logger, LogEventLevel level, string message)
public void EmitMessage(ILogger logger, DateTimeOffset timestamp, LogEventLevel level, string message)
{
if (IsEnabled(logger, level))
{
var logEvent = new LogEvent(logger.Issuer, DateTimeOffset.Now, level, message);

var logEvent = new LogEvent(logger.Issuer, timestamp, level, message);
foreach (var handler in Handlers)
{
handler.Handle(logEvent);
Expand Down
7 changes: 6 additions & 1 deletion dotnet/src/webdriver/Internal/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ public bool IsEnabled(LogEventLevel level)
return Log.CurrentContext.IsEnabled(this, level);
}

public void LogMessage(DateTimeOffset timestamp, LogEventLevel level, string message)
{
Log.CurrentContext.EmitMessage(this, timestamp.ToLocalTime(), level, message);
}

private void LogMessage(LogEventLevel level, string message)
{
Log.CurrentContext.EmitMessage(this, level, message);
LogMessage(DateTimeOffset.Now, level, message);
}
}
Loading
Loading