Skip to content

Commit e8d62bd

Browse files
committed
Merge remote-tracking branch 'upstream/trunk' into bidi-bytesvalue
2 parents 23634ef + f3361c3 commit e8d62bd

File tree

19 files changed

+112
-89
lines changed

19 files changed

+112
-89
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,47 @@ To automatically update and pin new dependencies, run:
210210

211211
### Python
212212

213-
You can run Python code locally by updating generated files in the python directory using:
213+
#### Linting
214+
215+
We follow the [PEP8 Style Guide for Python Code](https://peps.python.org/pep-0008) (except we use a 120 character line length).
216+
This is checked and enforced with several linting tools, including
217+
[black](https://pypi.org/project/black),
218+
[docformatter](https://pypi.org/project/docformatter),
219+
[flake8](https://flake8.pycqa.org),
220+
and [isort](https://pycqa.github.io/isort).
221+
222+
To run all of the linting tools:
214223
```shell
215-
./go py:update
224+
./go py:lint
216225
```
217226

218-
To install Selenium locally based on a specific commit, you can use:
227+
You need `tox` installed to run the linting tools (`pip install tox`).
228+
229+
#### Local Installation
230+
231+
To run Python code locally without building/installing the package, you must first install the dependencies:
232+
```shell
233+
pip install -r py/requirements.txt
234+
```
235+
236+
Then, build the generated files and copy them into your local source tree:
237+
```shell
238+
./go py:local_dev
239+
```
240+
241+
After that, you can import the selenium package directly from source from the `py` directory.
242+
243+
Instead of running from source, you can build and install the selenium package (wheel) locally:
219244
```shell
220245
./go py:install
221246
```
222247

248+
This will attempt to install into the global Python `site-packages` directory,
249+
which might not be writable. To avoid this, you should create and activate a
250+
[virtual environment](https://packaging.python.org/en/latest/tutorials/installing-packages/#creating-virtual-environments)
251+
before installing.
252+
253+
223254
### Ruby
224255

225256
Instead of using `irb`, you can create an interactive REPL with all gems loaded using: `bazel run //rb:console`

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
6666
[JsonSerializable(typeof(Modules.Script.RealmInfo.AudioWorklet))]
6767
[JsonSerializable(typeof(Modules.Script.RealmInfo.Worklet))]
6868

69-
[JsonSerializable(typeof(Modules.Log.Entry.Console))]
70-
[JsonSerializable(typeof(Modules.Log.Entry.Javascript))]
69+
[JsonSerializable(typeof(Modules.Log.ConsoleLogEntry))]
70+
[JsonSerializable(typeof(Modules.Log.JavascriptLogEntry))]
7171
#endregion
7272

7373
[JsonSerializable(typeof(Command))]
@@ -121,7 +121,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
121121
[JsonSerializable(typeof(Modules.BrowsingContext.UserPromptClosedEventArgs))]
122122
[JsonSerializable(typeof(Modules.BrowsingContext.Origin), TypeInfoPropertyName = "BrowsingContext_Origin")]
123123

124-
[JsonSerializable(typeof(Modules.Network.UrlPattern.String), TypeInfoPropertyName = "Network_UrlPattern_String")]
125124
[JsonSerializable(typeof(Modules.Network.ContinueWithAuthParameters.Default), TypeInfoPropertyName = "Network_ContinueWithAuthParameters_Default")]
126125
[JsonSerializable(typeof(Modules.Network.AddInterceptCommand))]
127126
[JsonSerializable(typeof(Modules.Network.AddInterceptResult))]
@@ -139,9 +138,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
139138
[JsonSerializable(typeof(Modules.Network.FetchErrorEventArgs))]
140139
[JsonSerializable(typeof(Modules.Network.AuthRequiredEventArgs))]
141140

142-
[JsonSerializable(typeof(Modules.Script.Target.Realm), TypeInfoPropertyName = "Script_Target_Realm")]
143-
[JsonSerializable(typeof(Modules.Script.Target.Context), TypeInfoPropertyName = "Script_Target_Context")]
144-
145141
[JsonSerializable(typeof(Modules.Script.AddPreloadScriptCommand))]
146142
[JsonSerializable(typeof(Modules.Script.AddPreloadScriptResult))]
147143
[JsonSerializable(typeof(Modules.Script.DisownCommand))]
@@ -156,7 +152,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
156152
[JsonSerializable(typeof(Modules.Script.RealmDestroyedEventArgs))]
157153
[JsonSerializable(typeof(IReadOnlyList<Modules.Script.RealmInfo>))]
158154

159-
[JsonSerializable(typeof(Modules.Log.Entry))]
155+
[JsonSerializable(typeof(Modules.Log.LogEntry))]
160156

161157
[JsonSerializable(typeof(Modules.Storage.GetCookiesCommand))]
162158
[JsonSerializable(typeof(Modules.Storage.GetCookiesResult))]

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@
2525
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic;
2626

2727
// https://github.com/dotnet/runtime/issues/72604
28-
internal class LogEntryConverter : JsonConverter<Modules.Log.Entry>
28+
internal class LogEntryConverter : JsonConverter<Modules.Log.LogEntry>
2929
{
30-
public override Modules.Log.Entry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
30+
public override Modules.Log.LogEntry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3131
{
3232
var jsonDocument = JsonDocument.ParseValue(ref reader);
3333

3434
return jsonDocument.RootElement.GetProperty("type").ToString() switch
3535
{
36-
"console" => jsonDocument.Deserialize<Modules.Log.Entry.Console>(options),
37-
"javascript" => jsonDocument.Deserialize<Modules.Log.Entry.Javascript>(options),
36+
"console" => jsonDocument.Deserialize<ConsoleLogEntry>(options),
37+
"javascript" => jsonDocument.Deserialize<JavascriptLogEntry>(options),
3838
_ => null,
3939
};
4040
}
4141

42-
public override void Write(Utf8JsonWriter writer, Modules.Log.Entry value, JsonSerializerOptions options)
42+
public override void Write(Utf8JsonWriter writer, Modules.Log.LogEntry value, JsonSerializerOptions options)
4343
{
4444
throw new NotImplementedException();
4545
}

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

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

2626
public class BrowsingContextLogModule(BrowsingContext context, LogModule logModule)
2727
{
28-
public Task<Subscription> OnEntryAddedAsync(Func<Entry, Task> handler, SubscriptionOptions? options = null)
28+
public Task<Subscription> OnEntryAddedAsync(Func<Log.LogEntry, Task> handler, SubscriptionOptions? options = null)
2929
{
3030
return logModule.OnEntryAddedAsync(async args =>
3131
{
@@ -36,7 +36,7 @@ public Task<Subscription> OnEntryAddedAsync(Func<Entry, Task> handler, Subscript
3636
}, options);
3737
}
3838

39-
public Task<Subscription> OnEntryAddedAsync(Action<Entry> handler, SubscriptionOptions? options = null)
39+
public Task<Subscription> OnEntryAddedAsync(Action<Log.LogEntry> handler, SubscriptionOptions? options = null)
4040
{
4141
return logModule.OnEntryAddedAsync(args =>
4242
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<IReadOnlyList<RealmInfo>> GetRealmsAsync(GetRealmsOptions? opt
4646

4747
public Task<EvaluateResult.Success> EvaluateAsync(string expression, bool awaitPromise, EvaluateOptions? options = null, ContextTargetOptions? targetOptions = null)
4848
{
49-
var contextTarget = new Target.Context(context);
49+
var contextTarget = new ContextTarget(context);
5050

5151
if (targetOptions is not null)
5252
{
@@ -65,7 +65,7 @@ public async Task<IReadOnlyList<RealmInfo>> GetRealmsAsync(GetRealmsOptions? opt
6565

6666
public Task<EvaluateResult.Success> CallFunctionAsync(string functionDeclaration, bool awaitPromise, CallFunctionOptions? options = null, ContextTargetOptions? targetOptions = null)
6767
{
68-
var contextTarget = new Target.Context(context);
68+
var contextTarget = new ContextTarget(context);
6969

7070
if (targetOptions is not null)
7171
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Task<GetCookiesResult> GetCookiesAsync(GetCookiesOptions? options = null)
2828
{
2929
options ??= new();
3030

31-
options.Partition = new PartitionDescriptor.Context(context);
31+
options.Partition = new ContextPartitionDescriptor(context);
3232

3333
return storageModule.GetCookiesAsync(options);
3434
}
@@ -37,7 +37,7 @@ public async Task<PartitionKey> DeleteCookiesAsync(DeleteCookiesOptions? options
3737
{
3838
options ??= new();
3939

40-
options.Partition = new PartitionDescriptor.Context(context);
40+
options.Partition = new ContextPartitionDescriptor(context);
4141

4242
var res = await storageModule.DeleteCookiesAsync(options).ConfigureAwait(false);
4343

@@ -48,7 +48,7 @@ public async Task<PartitionKey> SetCookieAsync(PartialCookie cookie, SetCookieOp
4848
{
4949
options ??= new();
5050

51-
options.Partition = new PartitionDescriptor.Context(context);
51+
options.Partition = new ContextPartitionDescriptor(context);
5252

5353
var res = await storageModule.SetCookieAsync(cookie, options).ConfigureAwait(false);
5454

dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs renamed to dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="Entry.cs" company="Selenium Committers">
1+
// <copyright file="LogEntry.cs" company="Selenium Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -24,19 +24,19 @@ namespace OpenQA.Selenium.BiDi.Modules.Log;
2424

2525
// https://github.com/dotnet/runtime/issues/72604
2626
//[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
27-
//[JsonDerivedType(typeof(Console), "console")]
28-
//[JsonDerivedType(typeof(Javascript), "javascript")]
29-
public abstract record Entry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp)
27+
//[JsonDerivedType(typeof(ConsoleLogEntry), "console")]
28+
//[JsonDerivedType(typeof(JavascriptLogEntry), "javascript")]
29+
public abstract record LogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp)
3030
: EventArgs(BiDi)
3131
{
3232
public Script.StackTrace? StackTrace { get; set; }
33+
}
3334

34-
public record Console(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp, string Method, IReadOnlyList<Script.RemoteValue> Args)
35-
: Entry(BiDi, Level, Source, Text, Timestamp);
35+
public record ConsoleLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp, string Method, IReadOnlyList<Script.RemoteValue> Args)
36+
: LogEntry(BiDi, Level, Source, Text, Timestamp);
3637

37-
public record Javascript(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp)
38-
: Entry(BiDi, Level, Source, Text, Timestamp);
39-
}
38+
public record JavascriptLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp)
39+
: LogEntry(BiDi, Level, Source, Text, Timestamp);
4040

4141
public enum Level
4242
{

dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ namespace OpenQA.Selenium.BiDi.Modules.Log;
2525

2626
public sealed class LogModule(Broker broker) : Module(broker)
2727
{
28-
public async Task<Subscription> OnEntryAddedAsync(Func<Entry, Task> handler, SubscriptionOptions? options = null)
28+
public async Task<Subscription> OnEntryAddedAsync(Func<LogEntry, Task> handler, SubscriptionOptions? options = null)
2929
{
3030
return await Broker.SubscribeAsync("log.entryAdded", handler, options).ConfigureAwait(false);
3131
}
3232

33-
public async Task<Subscription> OnEntryAddedAsync(Action<Entry> handler, SubscriptionOptions? options = null)
33+
public async Task<Subscription> OnEntryAddedAsync(Action<LogEntry> handler, SubscriptionOptions? options = null)
3434
{
3535
return await Broker.SubscribeAsync("log.entryAdded", handler, options).ConfigureAwait(false);
3636
}

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,24 @@
2222
namespace OpenQA.Selenium.BiDi.Modules.Network;
2323

2424
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
25-
[JsonDerivedType(typeof(Pattern), "pattern")]
26-
[JsonDerivedType(typeof(String), "string")]
25+
[JsonDerivedType(typeof(PatternUrlPattern), "pattern")]
26+
[JsonDerivedType(typeof(StringUrlPattern), "string")]
2727
public abstract record UrlPattern
2828
{
29-
public static implicit operator UrlPattern(string value) => new String(value);
30-
31-
public record Pattern : UrlPattern
32-
{
33-
public string? Protocol { get; set; }
29+
public static implicit operator UrlPattern(string value) => new StringUrlPattern(value);
30+
}
3431

35-
public string? Hostname { get; set; }
32+
public record PatternUrlPattern : UrlPattern
33+
{
34+
public string? Protocol { get; set; }
3635

37-
public string? Port { get; set; }
36+
public string? Hostname { get; set; }
3837

39-
public string? Pathname { get; set; }
38+
public string? Port { get; set; }
4039

41-
public string? Search { get; set; }
42-
}
40+
public string? Pathname { get; set; }
4341

44-
public record String(string Pattern) : UrlPattern
45-
{
46-
public new string Pattern { get; } = Pattern;
47-
}
42+
public string? Search { get; set; }
4843
}
44+
45+
public record StringUrlPattern(string Pattern) : UrlPattern;

dotnet/src/webdriver/BiDi/Modules/Script/Target.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121

2222
namespace OpenQA.Selenium.BiDi.Modules.Script;
2323

24-
[JsonDerivedType(typeof(Realm))]
25-
[JsonDerivedType(typeof(Context))]
26-
public abstract record Target
27-
{
28-
public record Realm([property: JsonPropertyName("realm")] Script.Realm Target) : Target;
24+
[JsonDerivedType(typeof(RealmTarget))]
25+
[JsonDerivedType(typeof(ContextTarget))]
26+
public abstract record Target;
27+
28+
public record RealmTarget(Realm Realm) : Target;
2929

30-
public record Context([property: JsonPropertyName("context")] BrowsingContext.BrowsingContext Target) : Target
31-
{
32-
public string? Sandbox { get; set; }
33-
}
30+
public record ContextTarget(BrowsingContext.BrowsingContext Context) : Target
31+
{
32+
public string? Sandbox { get; set; }
3433
}
3534

3635
public class ContextTargetOptions

0 commit comments

Comments
 (0)