Skip to content

Commit 42326c4

Browse files
nvborisenkosandeepsuryaprasad
authored andcommitted
[dotnet] Improve bidi exception when it is not enabled (SeleniumHQ#15163)
1 parent 0de69a9 commit 42326c4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// </copyright>
1919

2020
using OpenQA.Selenium.BiDi.Modules.BrowsingContext;
21+
using System;
2122
using System.Threading.Tasks;
2223

2324
#nullable enable
@@ -28,11 +29,18 @@ public static class WebDriverExtensions
2829
{
2930
public static async Task<BiDi> AsBiDiAsync(this IWebDriver webDriver)
3031
{
31-
var webSocketUrl = ((IHasCapabilities)webDriver).Capabilities.GetCapability("webSocketUrl");
32+
if (webDriver is null) throw new ArgumentNullException(nameof(webDriver));
3233

33-
if (webSocketUrl is null) throw new System.Exception("The driver is not compatible with bidirectional protocol or it is not enabled in driver options.");
34+
string? webSocketUrl = null;
3435

35-
var bidi = await BiDi.ConnectAsync(webSocketUrl.ToString()!).ConfigureAwait(false);
36+
if (webDriver is IHasCapabilities hasCapabilities)
37+
{
38+
webSocketUrl = hasCapabilities.Capabilities.GetCapability("webSocketUrl")?.ToString();
39+
}
40+
41+
if (webSocketUrl is null) throw new BiDiException("The driver is not compatible with bidirectional protocol or \"webSocketUrl\" not enabled in driver options.");
42+
43+
var bidi = await BiDi.ConnectAsync(webSocketUrl).ConfigureAwait(false);
3644

3745
return bidi;
3846
}

0 commit comments

Comments
 (0)