Skip to content

Commit d274da7

Browse files
committed
[dotnet] Lazy-load Selenium manager binary location
1 parent d922168 commit d274da7

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,28 @@ public static class SeleniumManager
3636
{
3737
private static readonly ILogger _logger = Log.GetLogger(typeof(SeleniumManager));
3838

39-
private static readonly string BinaryFullPath = Environment.GetEnvironmentVariable("SE_MANAGER_PATH");
39+
private static string? _binaryFullPath;
40+
private static string BinaryFullPath => _binaryFullPath ??= GetBinaryFullPath();
4041

4142
private static readonly JsonSerializerOptions _serializerOptions = new() { PropertyNameCaseInsensitive = true, TypeInfoResolver = SeleniumManagerSerializerContext.Default };
4243

43-
static SeleniumManager()
44+
private static string GetBinaryFullPath()
4445
{
45-
46-
if (BinaryFullPath == null)
46+
string? binaryFullPath = Environment.GetEnvironmentVariable("SE_MANAGER_PATH");
47+
if (binaryFullPath == null)
4748
{
4849
var currentDirectory = AppContext.BaseDirectory;
4950
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
5051
{
51-
BinaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "windows", "selenium-manager.exe");
52+
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "windows", "selenium-manager.exe");
5253
}
5354
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
5455
{
55-
BinaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "linux", "selenium-manager");
56+
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "linux", "selenium-manager");
5657
}
5758
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
5859
{
59-
BinaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "macos", "selenium-manager");
60+
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "macos", "selenium-manager");
6061
}
6162
else
6263
{
@@ -65,10 +66,11 @@ static SeleniumManager()
6566
}
6667
}
6768

68-
if (!File.Exists(BinaryFullPath))
69+
if (!File.Exists(binaryFullPath))
6970
{
70-
throw new WebDriverException($"Unable to locate or obtain Selenium Manager binary at {BinaryFullPath}");
71+
throw new WebDriverException($"Unable to locate or obtain Selenium Manager binary at {binaryFullPath}");
7172
}
73+
return binaryFullPath;
7274
}
7375

7476
/// <summary>

0 commit comments

Comments
 (0)