Skip to content

[dotnet] Enhance Selenium Manager platform detection #15649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2025
Merged
Changes from all commits
Commits
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
45 changes: 37 additions & 8 deletions dotnet/src/webdriver/SeleniumManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,46 @@ public static class SeleniumManager
string? binaryFullPath = Environment.GetEnvironmentVariable("SE_MANAGER_PATH");
if (binaryFullPath == null)
{
var currentDirectory = AppContext.BaseDirectory;
SupportedPlatform? platform = null;

#if NET8_0_OR_GREATER
if (OperatingSystem.IsWindows())
{
platform = SupportedPlatform.Windows;
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsFreeBSD())
{
platform = SupportedPlatform.Linux;
}
else if (OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst())
{
platform = SupportedPlatform.MacOS;
}
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "windows", "selenium-manager.exe");
platform = SupportedPlatform.Windows;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "linux", "selenium-manager");
platform = SupportedPlatform.Linux;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "macos", "selenium-manager");
platform = SupportedPlatform.MacOS;
}
else
#endif

var currentDirectory = AppContext.BaseDirectory;

binaryFullPath = platform switch
{
throw new PlatformNotSupportedException(
$"Selenium Manager doesn't support your runtime platform: {RuntimeInformation.OSDescription}");
}
SupportedPlatform.Windows => Path.Combine(currentDirectory, "selenium-manager", "windows", "selenium-manager.exe"),
SupportedPlatform.Linux => Path.Combine(currentDirectory, "selenium-manager", "linux", "selenium-manager"),
SupportedPlatform.MacOS => Path.Combine(currentDirectory, "selenium-manager", "macos", "selenium-manager"),
_ => throw new PlatformNotSupportedException(
$"Selenium Manager doesn't support your runtime platform: {RuntimeInformation.OSDescription}"),
};
}

if (!File.Exists(binaryFullPath))
Expand Down Expand Up @@ -225,4 +247,11 @@ string BrowserPath
[JsonSerializable(typeof(SeleniumManagerResponse))]
[JsonSourceGenerationOptions(PropertyNameCaseInsensitive = true)]
internal sealed partial class SeleniumManagerSerializerContext : JsonSerializerContext;

internal enum SupportedPlatform
{
Windows,
Linux,
MacOS
}
}
Loading