Skip to content

Commit 69ccfe4

Browse files
nvborisenkodiemol
andauthored
[dotnet] Avoid try/catch while working with known types in Selenium Manager (#12051)
Avoid try/catch while working with known types Co-authored-by: Diego Molina <[email protected]>
1 parent 0d08c74 commit 69ccfe4

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ static SeleniumManager()
5353
#if NET45 || NET46 || NET47
5454
binary = "selenium-manager/windows/selenium-manager.exe";
5555
#else
56-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
57-
{
58-
binary = "selenium-manager/windows/selenium-manager.exe";
59-
}
60-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
61-
{
62-
binary = "selenium-manager/linux/selenium-manager";
63-
}
64-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
65-
{
66-
binary = "selenium-manager/macos/selenium-manager";
67-
}
68-
else
69-
{
70-
throw new WebDriverException("Selenium Manager did not find supported operating system");
71-
}
56+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
57+
{
58+
binary = "selenium-manager/windows/selenium-manager.exe";
59+
}
60+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
61+
{
62+
binary = "selenium-manager/linux/selenium-manager";
63+
}
64+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
65+
{
66+
binary = "selenium-manager/macos/selenium-manager";
67+
}
68+
else
69+
{
70+
throw new WebDriverException("Selenium Manager did not find supported operating system");
71+
}
7272
#endif
7373

7474
binaryFullPath = Path.Combine(currentDirectory, binary);
@@ -111,14 +111,11 @@ private static string BrowserBinary(DriverOptions options)
111111
string[] vendorOptionsCapabilities = { "moz:firefoxOptions", "goog:chromeOptions", "ms:edgeOptions" };
112112
foreach (string vendorOptionsCapability in vendorOptionsCapabilities)
113113
{
114-
try
115-
{
116-
Dictionary<string, object> vendorOptions = capabilities.GetCapability(vendorOptionsCapability) as Dictionary<string, object>;
117-
return vendorOptions["binary"] as string;
118-
}
119-
catch (Exception)
114+
IDictionary<string, object> vendorOptions = capabilities.GetCapability(vendorOptionsCapability) as IDictionary<string, object>;
115+
116+
if (vendorOptions != null && vendorOptions.TryGetValue("binary", out object browserBinaryPath))
120117
{
121-
// no-op, it would be ideal to at least log the exception but the C# do not log anything at the moment
118+
return browserBinaryPath as string;
122119
}
123120
}
124121

0 commit comments

Comments
 (0)