Skip to content

Commit

Permalink
[dotnet] add Selenium Manager support for linux & mac
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 3, 2022
1 parent ba1821d commit b0db1ee
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
14 changes: 14 additions & 0 deletions dotnet/src/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ copy_file(
out = "Selenium.WebDriver.targets",
)

copy_file(
name = "manager-linux",
src = "//common/manager:linux/selenium-manager",
out = "manager/linux/selenium-manager",
)

copy_file(
name = "manager-macos",
src = "//common/manager:macos/selenium-manager",
out = "manager/macos/selenium-manager",
)

copy_file(
name = "manager-windows",
src = "//common/manager:windows/selenium-manager.exe",
Expand All @@ -266,6 +278,8 @@ nuget_package(
deps = [
":logo",
":props",
":manager-linux",
":manager-macos",
":manager-windows",
":net45",
":net46",
Expand Down
40 changes: 29 additions & 11 deletions dotnet/src/webdriver/SeleniumManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
using System.Collections.Generic;
using System.Diagnostics;

#if !NETFRAMEWORK
using System.Runtime.InteropServices;
#endif

namespace OpenQA.Selenium
{
/// <summary>
Expand All @@ -30,9 +34,9 @@ public static class SeleniumManager
{
private static string binary;
private static readonly List<string> KnownDrivers = new List<string>() {
"geckodriver.exe",
"chromedriver.exe",
"msedgedriver.exe"
"geckodriver",
"chromedriver",
"msedgedriver"
};

/// <summary>
Expand All @@ -44,14 +48,15 @@ public static class SeleniumManager
/// </returns>
public static string DriverPath(string driverName)
{
driverName = driverName.Replace(".exe", "");
if (!KnownDrivers.Contains(driverName))
{
throw new WebDriverException("Unable to locate driver with name: " + driverName);
}
var binaryFile = Binary;
if (binaryFile == null) return null;

var arguments = "--driver " + driverName.Replace(".exe", "");
var arguments = "--driver " + driverName;
var output = RunCommand(binaryFile, arguments);
return output.Replace("INFO\t", "").TrimEnd();
}
Expand All @@ -65,13 +70,26 @@ private static string Binary
{
if (string.IsNullOrEmpty(binary))
{
// TODO Identify runtime platform
if (!Environment.OSVersion.Platform.ToString().StartsWith("Win"))
{
throw new WebDriverException("Selenium Manager only supports Windows in .NET at this time");
}

binary = "selenium-manager/windows/selenium-manager.exe";
#if NETFRAMEWORK
binary = "selenium-manager/windows/selenium-manager.exe";
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
binary = "selenium-manager/windows/selenium-manager.exe";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
binary = "selenium-manager/linux/selenium-manager";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
binary = "selenium-manager/macos/selenium-manager";
}
else
{
throw new WebDriverException("Selenium Manager did not find supported operating system");
}
#endif
}

return binary;
Expand Down
22 changes: 17 additions & 5 deletions dotnet/src/webdriver/build/Selenium.WebDriver.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\manager\windows\selenium-manager.exe">
<Link>selenium-manager\windows\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</None>
<None Include="$(MSBuildThisFileDirectory)..\manager\linux\selenium-manager">
<Link>selenium-manager\linux\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</None>

<None Include="$(MSBuildThisFileDirectory)..\manager\macos\selenium-manager">
<Link>selenium-manager\macos\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</None>

<None Include="$(MSBuildThisFileDirectory)..\manager\windows\selenium-manager.exe">
<Link>selenium-manager\windows\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</None>
</ItemGroup>

</Project>

0 comments on commit b0db1ee

Please sign in to comment.