Skip to content
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
14 changes: 11 additions & 3 deletions dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// </copyright>

using OpenQA.Selenium.BiDi.Modules.BrowsingContext;
using System;
using System.Threading.Tasks;

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

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

var bidi = await BiDi.ConnectAsync(webSocketUrl.ToString()!).ConfigureAwait(false);
if (webDriver is IHasCapabilities hasCapabilities)
{
webSocketUrl = hasCapabilities.Capabilities.GetCapability("webSocketUrl")?.ToString();
}

if (webSocketUrl is null) throw new BiDiException("The driver is not compatible with bidirectional protocol or \"webSocketUrl\" not enabled in driver options.");

var bidi = await BiDi.ConnectAsync(webSocketUrl).ConfigureAwait(false);

return bidi;
}
Expand Down
Loading