Skip to content

Commit e2bcb00

Browse files
committed
[dotnet] Selenium Manager use binary from Browser Options
#11351
1 parent 5cc42f2 commit e2bcb00

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,40 @@ public static string DriverPath(DriverOptions options)
6060
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --browser-version {0}", options.BrowserVersion);
6161
}
6262

63+
string browserBinary = BrowserBinary(options);
64+
if (!string.IsNullOrEmpty(browserBinary))
65+
{
66+
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --browser-path \"{0}\"", browserBinary);
67+
}
68+
69+
6370
return RunCommand(binaryFile, argsBuilder.ToString());
6471
}
6572

73+
74+
/// <summary>
75+
/// Extracts the browser binary location from the vendor options when present. Only Chrome, Firefox, and Edge.
76+
/// </summary>
77+
private static string BrowserBinary(DriverOptions options)
78+
{
79+
ICapabilities capabilities = options.ToCapabilities();
80+
string[] vendorOptionsCapabilities = { "moz:firefoxOptions", "goog:chromeOptions", "ms:edgeOptions" };
81+
foreach (string vendorOptionsCapability in vendorOptionsCapabilities)
82+
{
83+
try
84+
{
85+
Dictionary<string, object> vendorOptions = capabilities.GetCapability(vendorOptionsCapability) as Dictionary<string, object>;
86+
return vendorOptions["binary"] as string;
87+
}
88+
catch (Exception)
89+
{
90+
// no-op, it would be ideal to at least log the exception but the C# do not log anything at the moment
91+
}
92+
}
93+
94+
return null;
95+
}
96+
6697
/// <summary>
6798
/// Gets the location of the correct Selenium Manager binary.
6899
/// </summary>

0 commit comments

Comments
 (0)