Skip to content

Commit 91209f9

Browse files
authored
Merge branch 'SeleniumHQ:trunk' into py-remote-options-kwarg
2 parents 348f49e + 12a1593 commit 91209f9

File tree

15 files changed

+549
-139
lines changed

15 files changed

+549
-139
lines changed

common/src/web/formPage.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@
8282

8383
<select id="invisible_multi_select" multiple>
8484
<option selected="selected" value="apples" style="opacity: 0;">Apples</option>
85-
<option value="oranges">Oranges</option>
86-
<option selected="selected" value="lemons">Lemons</option>
85+
<option value="pears" style="opacity: 0.0;">Pears</option>
86+
<option value="oranges" style="display: none;">Oranges</option>
87+
<option selected="selected" value="lemons" style="visibility: hidden;">Lemons</option>
8788
</select>
8889

8990
<select name="select-default">

dotnet/src/webdriver/BiDi/Communication/Broker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ internal Broker(BiDi bidi, Uri url)
7676
new BrowserClientWindowConverter(),
7777
new NavigationConverter(),
7878
new InterceptConverter(_bidi),
79-
new RequestConverter(_bidi),
79+
new RequestConverter(),
8080
new ChannelConverter(),
8181
new HandleConverter(_bidi),
8282
new InternalIdConverter(_bidi),

dotnet/src/webdriver/BiDi/Communication/Json/Converters/RequestConverter.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,11 @@ namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;
2626

2727
internal class RequestConverter : JsonConverter<Request>
2828
{
29-
private readonly BiDi _bidi;
30-
31-
public RequestConverter(BiDi bidi)
32-
{
33-
_bidi = bidi;
34-
}
35-
3629
public override Request? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3730
{
3831
var id = reader.GetString();
3932

40-
return new Request(_bidi, id!);
33+
return new Request(id!);
4134
}
4235

4336
public override void Write(Utf8JsonWriter writer, Request value, JsonSerializerOptions options)

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,50 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2525

2626
public class BrowsingContextNetworkModule(BrowsingContext context, NetworkModule networkModule)
2727
{
28-
public async Task<Intercept> InterceptRequestAsync(Func<BeforeRequestSentEventArgs, Task> handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
28+
public async Task<Intercept> InterceptRequestAsync(Func<InterceptedRequest, Task> handler, InterceptRequestOptions? options = null)
2929
{
30-
AddInterceptOptions addInterceptOptions = new(interceptOptions)
30+
AddInterceptOptions addInterceptOptions = new(options)
3131
{
3232
Contexts = [context]
3333
};
3434

3535
var intercept = await networkModule.AddInterceptAsync([InterceptPhase.BeforeRequestSent], addInterceptOptions).ConfigureAwait(false);
3636

37-
await intercept.OnBeforeRequestSentAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }).ConfigureAwait(false);
37+
await intercept.OnBeforeRequestSentAsync(
38+
async req => await handler(new(req.BiDi, req.Context, req.IsBlocked, req.Navigation, req.RedirectCount, req.Request, req.Timestamp, req.Initiator)),
39+
new BrowsingContextsSubscriptionOptions(null) { Contexts = [context] }).ConfigureAwait(false);
3840

3941
return intercept;
4042
}
4143

42-
public async Task<Intercept> InterceptResponseAsync(Func<ResponseStartedEventArgs, Task> handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
44+
public async Task<Intercept> InterceptResponseAsync(Func<InterceptedResponse, Task> handler, InterceptResponseOptions? options = null)
4345
{
44-
AddInterceptOptions addInterceptOptions = new(interceptOptions)
46+
AddInterceptOptions addInterceptOptions = new(options)
4547
{
4648
Contexts = [context]
4749
};
4850

4951
var intercept = await networkModule.AddInterceptAsync([InterceptPhase.ResponseStarted], addInterceptOptions).ConfigureAwait(false);
5052

51-
await intercept.OnResponseStartedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }).ConfigureAwait(false);
53+
await intercept.OnResponseStartedAsync(
54+
async res => await handler(new(res.BiDi, res.Context, res.IsBlocked, res.Navigation, res.RedirectCount, res.Request, res.Timestamp, res.Response)),
55+
new BrowsingContextsSubscriptionOptions(null) { Contexts = [context] }).ConfigureAwait(false);
5256

5357
return intercept;
5458
}
5559

56-
public async Task<Intercept> InterceptAuthAsync(Func<AuthRequiredEventArgs, Task> handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
60+
public async Task<Intercept> InterceptAuthAsync(Func<InterceptedAuth, Task> handler, InterceptAuthOptions? options = null)
5761
{
58-
AddInterceptOptions addInterceptOptions = new(interceptOptions)
62+
AddInterceptOptions addInterceptOptions = new(options)
5963
{
6064
Contexts = [context]
6165
};
6266

6367
var intercept = await networkModule.AddInterceptAsync([InterceptPhase.AuthRequired], addInterceptOptions).ConfigureAwait(false);
6468

65-
await intercept.OnAuthRequiredAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }).ConfigureAwait(false);
69+
await intercept.OnAuthRequiredAsync(
70+
async auth => await handler(new(auth.BiDi, auth.Context, auth.IsBlocked, auth.Navigation, auth.RedirectCount, auth.Request, auth.Timestamp, auth.Response)),
71+
new BrowsingContextsSubscriptionOptions(null) { Contexts = [context] }).ConfigureAwait(false);
6672

6773
return intercept;
6874
}
@@ -127,3 +133,9 @@ public Task<Subscription> OnAuthRequiredAsync(Action<AuthRequiredEventArgs> hand
127133
return networkModule.OnAuthRequiredAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] });
128134
}
129135
}
136+
137+
public record InterceptRequestOptions : BrowsingContextAddInterceptOptions;
138+
139+
public record InterceptResponseOptions : BrowsingContextAddInterceptOptions;
140+
141+
public record InterceptAuthOptions : BrowsingContextAddInterceptOptions;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// <copyright file="NetworkModule.HighLevel.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System;
21+
using System.Threading.Tasks;
22+
23+
namespace OpenQA.Selenium.BiDi.Modules.Network;
24+
25+
public partial class NetworkModule
26+
{
27+
public async Task<Intercept> InterceptRequestAsync(Func<InterceptedRequest, Task> handler, InterceptRequestOptions? options = null)
28+
{
29+
var intercept = await AddInterceptAsync([InterceptPhase.BeforeRequestSent], options).ConfigureAwait(false);
30+
31+
await intercept.OnBeforeRequestSentAsync(async req => await handler(new(req.BiDi, req.Context, req.IsBlocked, req.Navigation, req.RedirectCount, req.Request, req.Timestamp, req.Initiator))).ConfigureAwait(false);
32+
33+
return intercept;
34+
}
35+
36+
public async Task<Intercept> InterceptResponseAsync(Func<InterceptedResponse, Task> handler, InterceptResponseOptions? options = null)
37+
{
38+
var intercept = await AddInterceptAsync([InterceptPhase.ResponseStarted], options).ConfigureAwait(false);
39+
40+
await intercept.OnResponseStartedAsync(async res => await handler(new(res.BiDi, res.Context, res.IsBlocked, res.Navigation, res.RedirectCount, res.Request, res.Timestamp, res.Response))).ConfigureAwait(false);
41+
42+
return intercept;
43+
}
44+
45+
public async Task<Intercept> InterceptAuthAsync(Func<InterceptedAuth, Task> handler, InterceptAuthOptions? options = null)
46+
{
47+
var intercept = await AddInterceptAsync([InterceptPhase.AuthRequired], options).ConfigureAwait(false);
48+
49+
await intercept.OnAuthRequiredAsync(async auth => await handler(new(auth.BiDi, auth.Context, auth.IsBlocked, auth.Navigation, auth.RedirectCount, auth.Request, auth.Timestamp, auth.Response))).ConfigureAwait(false);
50+
51+
return intercept;
52+
}
53+
}
54+
55+
public record InterceptRequestOptions : AddInterceptOptions;
56+
57+
public record InterceptResponseOptions : AddInterceptOptions;
58+
59+
public record InterceptAuthOptions : AddInterceptOptions;
60+
61+
public record InterceptedRequest(BiDi BiDi, BrowsingContext.BrowsingContext Context, bool IsBlocked, BrowsingContext.Navigation Navigation, long RedirectCount, RequestData Request, DateTimeOffset Timestamp, Initiator Initiator)
62+
: BeforeRequestSentEventArgs(BiDi, Context, IsBlocked, Navigation, RedirectCount, Request, Timestamp, Initiator)
63+
{
64+
public Task ContinueAsync(ContinueRequestOptions? options = null)
65+
{
66+
return BiDi.Network.ContinueRequestAsync(Request.Request, options);
67+
}
68+
69+
public Task FailAsync()
70+
{
71+
return BiDi.Network.FailRequestAsync(Request.Request);
72+
}
73+
74+
public Task ProvideResponseAsync(ProvideResponseOptions? options = null)
75+
{
76+
return BiDi.Network.ProvideResponseAsync(Request.Request, options);
77+
}
78+
}
79+
80+
public record InterceptedResponse(BiDi BiDi, BrowsingContext.BrowsingContext Context, bool IsBlocked, BrowsingContext.Navigation Navigation, long RedirectCount, RequestData Request, DateTimeOffset Timestamp, ResponseData Response)
81+
: ResponseStartedEventArgs(BiDi, Context, IsBlocked, Navigation, RedirectCount, Request, Timestamp, Response)
82+
{
83+
public Task ContinueAsync(ContinueResponseOptions? options = null)
84+
{
85+
return BiDi.Network.ContinueResponseAsync(Request.Request, options);
86+
}
87+
}
88+
89+
public record InterceptedAuth(BiDi BiDi, BrowsingContext.BrowsingContext Context, bool IsBlocked, BrowsingContext.Navigation Navigation, long RedirectCount, RequestData Request, DateTimeOffset Timestamp, ResponseData Response)
90+
: AuthRequiredEventArgs(BiDi, Context, IsBlocked, Navigation, RedirectCount, Request, Timestamp, Response)
91+
{
92+
public Task ContinueAsync(AuthCredentials credentials, ContinueWithAuthCredentialsOptions? options = null)
93+
{
94+
return BiDi.Network.ContinueWithAuthAsync(Request.Request, credentials, options);
95+
}
96+
97+
public Task ContinueAsync(ContinueWithAuthDefaultCredentialsOptions? options = null)
98+
{
99+
return BiDi.Network.ContinueWithAuthAsync(Request.Request, options);
100+
}
101+
102+
public Task ContinueAsync(ContinueWithAuthCancelCredentialsOptions? options = null)
103+
{
104+
return BiDi.Network.ContinueWithAuthAsync(Request.Request, options);
105+
}
106+
}

dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace OpenQA.Selenium.BiDi.Modules.Network;
2626

27-
public sealed class NetworkModule(Broker broker) : Module(broker)
27+
public sealed partial class NetworkModule(Broker broker) : Module(broker)
2828
{
2929
internal async Task<Intercept> AddInterceptAsync(IEnumerable<InterceptPhase> phases, AddInterceptOptions? options = null)
3030
{
@@ -42,40 +42,13 @@ internal async Task RemoveInterceptAsync(Intercept intercept, RemoveInterceptOpt
4242
await Broker.ExecuteCommandAsync(new RemoveInterceptCommand(@params), options).ConfigureAwait(false);
4343
}
4444

45-
public async Task<Intercept> InterceptRequestAsync(Func<BeforeRequestSentEventArgs, Task> handler, AddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
46-
{
47-
var intercept = await AddInterceptAsync([InterceptPhase.BeforeRequestSent], interceptOptions).ConfigureAwait(false);
48-
49-
await intercept.OnBeforeRequestSentAsync(handler, options).ConfigureAwait(false);
50-
51-
return intercept;
52-
}
53-
54-
public async Task<Intercept> InterceptResponseAsync(Func<ResponseStartedEventArgs, Task> handler, AddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
55-
{
56-
var intercept = await AddInterceptAsync([InterceptPhase.ResponseStarted], interceptOptions).ConfigureAwait(false);
57-
58-
await intercept.OnResponseStartedAsync(handler, options).ConfigureAwait(false);
59-
60-
return intercept;
61-
}
62-
6345
public async Task SetCacheBehaviorAsync(CacheBehavior behavior, SetCacheBehaviorOptions? options = null)
6446
{
6547
var @params = new SetCacheBehaviorCommandParameters(behavior, options?.Contexts);
6648

6749
await Broker.ExecuteCommandAsync(new SetCacheBehaviorCommand(@params), options).ConfigureAwait(false);
6850
}
6951

70-
public async Task<Intercept> InterceptAuthAsync(Func<AuthRequiredEventArgs, Task> handler, AddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
71-
{
72-
var intercept = await AddInterceptAsync([InterceptPhase.AuthRequired], interceptOptions).ConfigureAwait(false);
73-
74-
await intercept.OnAuthRequiredAsync(handler, options).ConfigureAwait(false);
75-
76-
return intercept;
77-
}
78-
7952
internal async Task ContinueRequestAsync(Request request, ContinueRequestOptions? options = null)
8053
{
8154
var @params = new ContinueRequestCommandParameters(request, options?.Body, options?.Cookies, options?.Headers, options?.Method, options?.Url);

dotnet/src/webdriver/BiDi/Modules/Network/Request.cs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,14 @@
1717
// under the License.
1818
// </copyright>
1919

20-
using System.Threading.Tasks;
21-
2220
namespace OpenQA.Selenium.BiDi.Modules.Network;
2321

2422
public class Request
2523
{
26-
private readonly BiDi _bidi;
27-
28-
internal Request(BiDi bidi, string id)
24+
internal Request(string id)
2925
{
30-
_bidi = bidi;
3126
Id = id;
3227
}
3328

3429
public string Id { get; private set; }
35-
36-
public Task ContinueAsync(ContinueRequestOptions? options = null)
37-
{
38-
return _bidi.Network.ContinueRequestAsync(this, options);
39-
}
40-
41-
public Task FailAsync()
42-
{
43-
return _bidi.Network.FailRequestAsync(this);
44-
}
45-
46-
public Task ProvideResponseAsync(ProvideResponseOptions? options = null)
47-
{
48-
return _bidi.Network.ProvideResponseAsync(this, options);
49-
}
50-
51-
public Task ContinueResponseAsync(ContinueResponseOptions? options = null)
52-
{
53-
return _bidi.Network.ContinueResponseAsync(this, options);
54-
}
55-
56-
public Task ContinueWithAuthAsync(AuthCredentials credentials, ContinueWithAuthCredentialsOptions? options = null)
57-
{
58-
return _bidi.Network.ContinueWithAuthAsync(this, credentials, options);
59-
}
60-
61-
public Task ContinueWithAuthAsync(ContinueWithAuthDefaultCredentialsOptions? options = null)
62-
{
63-
return _bidi.Network.ContinueWithAuthAsync(this, options);
64-
}
65-
66-
public Task ContinueWithAuthAsync(ContinueWithAuthCancelCredentialsOptions? options = null)
67-
{
68-
return _bidi.Network.ContinueWithAuthAsync(this, options);
69-
}
7030
}

0 commit comments

Comments
 (0)