Skip to content

Commit 3e8b34c

Browse files
authored
[dotnet] BiDi implementation (#14318)
* Migrate * Use CLS compliant long instead of ulong * Use null instead of default for optional arguments * Use internal logging in websockettransport * Use internal logger in broker * Even with error log level * Simplify AsBidirectionalContextAsync * Fix ConfigureAwait in network module * Hide direct network interception * Rework public adding interception * Simplify network interception * Don't end session when disposing bidi driver
1 parent 7b5f6d7 commit 3e8b34c

File tree

138 files changed

+4387
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+4387
-0
lines changed

‎dotnet/src/webdriver/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ csharp_library(
5252
],
5353
deps = [
5454
framework("nuget", "NETStandard.Library"),
55+
framework("nuget", "Microsoft.Bcl.AsyncInterfaces"),
56+
framework("nuget", "System.Threading.Tasks.Extensions"),
5557
framework("nuget", "System.Memory"),
5658
framework("nuget", "System.Text.Json"),
5759
],
@@ -111,6 +113,8 @@ csharp_library(
111113
],
112114
deps = [
113115
framework("nuget", "NETStandard.Library"),
116+
framework("nuget", "Microsoft.Bcl.AsyncInterfaces"),
117+
framework("nuget", "System.Threading.Tasks.Extensions"),
114118
framework("nuget", "System.Memory"),
115119
framework("nuget", "System.Text.Json"),
116120
],

‎dotnet/src/webdriver/BiDi/BiDi.cs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using OpenQA.Selenium.BiDi.Communication;
5+
using OpenQA.Selenium.BiDi.Communication.Transport;
6+
7+
namespace OpenQA.Selenium.BiDi;
8+
9+
public class BiDi : IAsyncDisposable
10+
{
11+
private readonly ITransport _transport;
12+
private readonly Broker _broker;
13+
14+
private readonly Lazy<Modules.Session.SessionModule> _sessionModule;
15+
private readonly Lazy<Modules.BrowsingContext.BrowsingContextModule> _browsingContextModule;
16+
private readonly Lazy<Modules.Browser.BrowserModule> _browserModule;
17+
private readonly Lazy<Modules.Network.NetworkModule> _networkModule;
18+
private readonly Lazy<Modules.Input.InputModule> _inputModule;
19+
private readonly Lazy<Modules.Script.ScriptModule> _scriptModule;
20+
private readonly Lazy<Modules.Log.LogModule> _logModule;
21+
private readonly Lazy<Modules.Storage.StorageModule> _storageModule;
22+
23+
internal BiDi(string url)
24+
{
25+
var uri = new Uri(url);
26+
27+
_transport = new WebSocketTransport(new Uri(url));
28+
_broker = new Broker(this, _transport);
29+
30+
_sessionModule = new Lazy<Modules.Session.SessionModule>(() => new Modules.Session.SessionModule(_broker));
31+
_browsingContextModule = new Lazy<Modules.BrowsingContext.BrowsingContextModule>(() => new Modules.BrowsingContext.BrowsingContextModule(_broker));
32+
_browserModule = new Lazy<Modules.Browser.BrowserModule>(() => new Modules.Browser.BrowserModule(_broker));
33+
_networkModule = new Lazy<Modules.Network.NetworkModule>(() => new Modules.Network.NetworkModule(_broker));
34+
_inputModule = new Lazy<Modules.Input.InputModule>(() => new Modules.Input.InputModule(_broker));
35+
_scriptModule = new Lazy<Modules.Script.ScriptModule>(() => new Modules.Script.ScriptModule(_broker));
36+
_logModule = new Lazy<Modules.Log.LogModule>(() => new Modules.Log.LogModule(_broker));
37+
_storageModule = new Lazy<Modules.Storage.StorageModule>(() => new Modules.Storage.StorageModule(_broker));
38+
}
39+
40+
internal Modules.Session.SessionModule SessionModule => _sessionModule.Value;
41+
internal Modules.BrowsingContext.BrowsingContextModule BrowsingContextModule => _browsingContextModule.Value;
42+
public Modules.Browser.BrowserModule Browser => _browserModule.Value;
43+
public Modules.Network.NetworkModule Network => _networkModule.Value;
44+
internal Modules.Input.InputModule InputModule => _inputModule.Value;
45+
internal Modules.Script.ScriptModule ScriptModule => _scriptModule.Value;
46+
public Modules.Log.LogModule Log => _logModule.Value;
47+
public Modules.Storage.StorageModule Storage => _storageModule.Value;
48+
49+
public Task<Modules.Session.StatusResult> StatusAsync()
50+
{
51+
return SessionModule.StatusAsync();
52+
}
53+
54+
public static async Task<BiDi> ConnectAsync(string url)
55+
{
56+
var bidi = new BiDi(url);
57+
58+
await bidi._broker.ConnectAsync(default).ConfigureAwait(false);
59+
60+
return bidi;
61+
}
62+
63+
public Task<Modules.BrowsingContext.BrowsingContext> CreateBrowsingContextAsync(Modules.BrowsingContext.BrowsingContextType type, Modules.BrowsingContext.CreateOptions? options = null)
64+
{
65+
return BrowsingContextModule.CreateAsync(type, options);
66+
}
67+
68+
public Task<IReadOnlyList<Modules.BrowsingContext.BrowsingContextInfo>> GetBrowsingContextTreeAsync(Modules.BrowsingContext.GetTreeOptions? options = null)
69+
{
70+
return BrowsingContextModule.GetTreeAsync(options);
71+
}
72+
73+
public Task EndAsync(Modules.Session.EndOptions? options = null)
74+
{
75+
return SessionModule.EndAsync(options);
76+
}
77+
78+
public async ValueTask DisposeAsync()
79+
{
80+
await _broker.DisposeAsync().ConfigureAwait(false);
81+
82+
_transport?.Dispose();
83+
}
84+
85+
public Task<Subscription> OnBrowsingContextCreatedAsync(Func<Modules.BrowsingContext.BrowsingContextInfo, Task> handler, BrowsingContextsSubscriptionOptions? options = null)
86+
{
87+
return BrowsingContextModule.OnContextCreatedAsync(handler, options);
88+
}
89+
90+
public Task<Subscription> OnBrowsingContextCreatedAsync(Action<Modules.BrowsingContext.BrowsingContextInfo> handler, BrowsingContextsSubscriptionOptions? options = null)
91+
{
92+
return BrowsingContextModule.OnContextCreatedAsync(handler, options);
93+
}
94+
95+
public Task<Subscription> OnBrowsingContextDestroyedAsync(Func<Modules.BrowsingContext.BrowsingContextInfo, Task> handler, BrowsingContextsSubscriptionOptions? options = null)
96+
{
97+
return BrowsingContextModule.OnContextDestroyedAsync(handler, options);
98+
}
99+
100+
public Task<Subscription> OnBrowsingContextDestroyedAsync(Action<Modules.BrowsingContext.BrowsingContextInfo> handler, BrowsingContextsSubscriptionOptions? options = null)
101+
{
102+
return BrowsingContextModule.OnContextDestroyedAsync(handler, options);
103+
}
104+
105+
public Task<Subscription> OnUserPromptOpenedAsync(Func<Modules.BrowsingContext.UserPromptOpenedEventArgs, Task> handler, BrowsingContextsSubscriptionOptions? options = null)
106+
{
107+
return BrowsingContextModule.OnUserPromptOpenedAsync(handler, options);
108+
}
109+
110+
public Task<Subscription> OnUserPromptOpenedAsync(Action<Modules.BrowsingContext.UserPromptOpenedEventArgs> handler, BrowsingContextsSubscriptionOptions? options = null)
111+
{
112+
return BrowsingContextModule.OnUserPromptOpenedAsync(handler, options);
113+
}
114+
115+
public Task<Subscription> OnUserPromptClosedAsync(Func<Modules.BrowsingContext.UserPromptClosedEventArgs, Task> handler, BrowsingContextsSubscriptionOptions? options = null)
116+
{
117+
return BrowsingContextModule.OnUserPromptClosedAsync(handler, options);
118+
}
119+
120+
public Task<Subscription> OnUserPromptClosedAsync(Action<Modules.BrowsingContext.UserPromptClosedEventArgs> handler, BrowsingContextsSubscriptionOptions? options = null)
121+
{
122+
return BrowsingContextModule.OnUserPromptClosedAsync(handler, options);
123+
}
124+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace OpenQA.Selenium.BiDi;
4+
5+
public class BiDiException : Exception
6+
{
7+
public BiDiException(string message) : base(message)
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)