Skip to content

Commit 727fae0

Browse files
authored
[dotnet] Enhance Selenium Manager platform detection (#15649)
1 parent f8ad18b commit 727fae0

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

dotnet/src/webdriver/SeleniumManager.cs

+37-8
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,46 @@ public static class SeleniumManager
4646
string? binaryFullPath = Environment.GetEnvironmentVariable("SE_MANAGER_PATH");
4747
if (binaryFullPath == null)
4848
{
49-
var currentDirectory = AppContext.BaseDirectory;
49+
SupportedPlatform? platform = null;
50+
51+
#if NET8_0_OR_GREATER
52+
if (OperatingSystem.IsWindows())
53+
{
54+
platform = SupportedPlatform.Windows;
55+
}
56+
else if (OperatingSystem.IsLinux() || OperatingSystem.IsFreeBSD())
57+
{
58+
platform = SupportedPlatform.Linux;
59+
}
60+
else if (OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst())
61+
{
62+
platform = SupportedPlatform.MacOS;
63+
}
64+
#else
5065
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
5166
{
52-
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "windows", "selenium-manager.exe");
67+
platform = SupportedPlatform.Windows;
5368
}
5469
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
5570
{
56-
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "linux", "selenium-manager");
71+
platform = SupportedPlatform.Linux;
5772
}
5873
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
5974
{
60-
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "macos", "selenium-manager");
75+
platform = SupportedPlatform.MacOS;
6176
}
62-
else
77+
#endif
78+
79+
var currentDirectory = AppContext.BaseDirectory;
80+
81+
binaryFullPath = platform switch
6382
{
64-
throw new PlatformNotSupportedException(
65-
$"Selenium Manager doesn't support your runtime platform: {RuntimeInformation.OSDescription}");
66-
}
83+
SupportedPlatform.Windows => Path.Combine(currentDirectory, "selenium-manager", "windows", "selenium-manager.exe"),
84+
SupportedPlatform.Linux => Path.Combine(currentDirectory, "selenium-manager", "linux", "selenium-manager"),
85+
SupportedPlatform.MacOS => Path.Combine(currentDirectory, "selenium-manager", "macos", "selenium-manager"),
86+
_ => throw new PlatformNotSupportedException(
87+
$"Selenium Manager doesn't support your runtime platform: {RuntimeInformation.OSDescription}"),
88+
};
6789
}
6890

6991
if (!File.Exists(binaryFullPath))
@@ -225,4 +247,11 @@ string BrowserPath
225247
[JsonSerializable(typeof(SeleniumManagerResponse))]
226248
[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)]
227249
internal sealed partial class SeleniumManagerSerializerContext : JsonSerializerContext;
250+
251+
internal enum SupportedPlatform
252+
{
253+
Windows,
254+
Linux,
255+
MacOS
256+
}
228257
}

0 commit comments

Comments
 (0)