Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Migration from Newtonsoft.Json to System.Text.Json package #14292

Merged
merged 51 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
cfb60aa
Preparation to use system.text.json v8
nvborisenko Jul 18, 2024
c246ccd
Use .net sdk 8 in csproj
nvborisenko Jul 18, 2024
37fc782
Update packages vias bazel paket
nvborisenko Jul 18, 2024
74244b1
Merge branch 'dotnet_system-json' into dotnet_sdk8
nvborisenko Jul 18, 2024
5e1b7e5
Bazel tests
nvborisenko Jul 18, 2024
09e9b3f
And toolchain v8
nvborisenko Jul 18, 2024
210a422
Pack webdriver
nvborisenko Jul 20, 2024
78b4e78
Strongnamed
nvborisenko Jul 20, 2024
cc05ec1
Generate devtools
nvborisenko Jul 20, 2024
1b0c162
Update WebDriver.csproj
nvborisenko Jul 20, 2024
e1e18ea
Migrate some objects
nvborisenko Jul 20, 2024
6d1b719
Enum converter
nvborisenko Jul 20, 2024
e580b7b
Devtools error parsing
nvborisenko Jul 20, 2024
c768750
Finally devtools
nvborisenko Jul 20, 2024
ee80568
Update ChromiumNetworkConditions.cs
nvborisenko Jul 20, 2024
bab763f
Update Command.cs
nvborisenko Jul 20, 2024
c2f65be
Update StackTraceElement.cs
nvborisenko Jul 20, 2024
f06df9f
Update Command.cs
nvborisenko Jul 20, 2024
00f6cf8
Update DomMutationData.cs
nvborisenko Jul 20, 2024
e749b2d
Update JavaScriptEngine.cs
nvborisenko Jul 20, 2024
3c04fd2
Update ReturnedCapabilities.cs
nvborisenko Jul 20, 2024
81c6f61
Update FirefoxExtension.cs
nvborisenko Jul 20, 2024
26e13fc
Update DriverOptions.cs
nvborisenko Jul 20, 2024
c0cd90d
Update RemoteSessionSettings.cs
nvborisenko Jul 20, 2024
2884ec2
Update Proxy.cs
nvborisenko Jul 20, 2024
95d3cca
Update SeleniumManager.cs
nvborisenko Jul 20, 2024
2d03278
Update Cookie.cs
nvborisenko Jul 20, 2024
168a18b
Update FirefoxProfile.cs
nvborisenko Jul 20, 2024
f4fe367
Update SeleniumManager.cs
nvborisenko Jul 20, 2024
e75b2e1
Remove absolutely incorrect tests for proxy type
nvborisenko Jul 20, 2024
37b4489
Update Response.cs
nvborisenko Jul 20, 2024
312f99b
Revert "Update FirefoxProfile.cs"
nvborisenko Jul 21, 2024
aa3126b
As dictionary
nvborisenko Jul 22, 2024
1fe2395
Fix numbers
nvborisenko Jul 22, 2024
1637924
Remove newtonsoftjson
nvborisenko Jul 22, 2024
b0389ff
Merge remote-tracking branch 'upstream/trunk' into dotnet_sdk8
nvborisenko Jul 22, 2024
f7621ac
Update Cookie.cs
nvborisenko Jul 22, 2024
cb7f422
Build and pack
nvborisenko Jul 22, 2024
4975ffa
Fix ci build
nvborisenko Jul 22, 2024
103c1c5
And tests bazel
nvborisenko Jul 22, 2024
f54a3be
Update BUILD.bazel
nvborisenko Jul 22, 2024
ed164ef
Update BUILD.bazel
nvborisenko Jul 22, 2024
c31bcf0
Fix bazel format
nvborisenko Jul 22, 2024
6bf7668
Update ProxyTest.cs
nvborisenko Jul 22, 2024
3159291
Update SeleniumManager.cs
nvborisenko Jul 22, 2024
e472752
Update DomMutationData.cs
nvborisenko Jul 22, 2024
ca09602
Update ChromiumNetworkConditions.cs
nvborisenko Jul 22, 2024
0b04afe
Return back command ctor
nvborisenko Jul 22, 2024
7dd3f04
Fix target frameworks in csproj and align lang version
nvborisenko Jul 23, 2024
cdae53a
Reuse json serializer options in command and response
nvborisenko Jul 23, 2024
30b021b
Merge branch 'trunk' into dotnet_sdk8
nvborisenko Jul 25, 2024
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
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use_repo(esbuild, "esbuild_toolchains")
register_toolchains("@esbuild_toolchains//:all")

dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet")
dotnet.toolchain(dotnet_version = "7.0.400")
dotnet.toolchain(dotnet_version = "8.0.203")
use_repo(dotnet, "dotnet_toolchains")

selenium_paket = use_extension("//dotnet:paket.nuget_extension.bzl", "nuget_extension")
Expand Down
2 changes: 1 addition & 1 deletion dotnet/paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ nuget System.Diagnostics.Tools 4.3.0
nuget System.Drawing.Common 7.0.0
nuget System.Runtime 4.3.1
nuget System.Runtime.InteropServices 4.3.0
nuget System.Text.Json 6.0.9
nuget System.Text.Json 8.0.4
nuget Runfiles 0.12.0
23 changes: 11 additions & 12 deletions dotnet/paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NUGET
System.Reflection.TypeExtensions (>= 4.4)
Humanizer.Core (2.8.26)
Microsoft.AspNetCore.App.Ref (6.0.9)
Microsoft.Bcl.AsyncInterfaces (7.0) - restriction: || (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp3.1)) (== netstandard2.0)
Microsoft.Bcl.AsyncInterfaces (8.0) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
Microsoft.CSharp (4.5)
Microsoft.Extensions.DependencyInjection (3.1.9)
Expand All @@ -42,7 +42,7 @@ NUGET
NETStandard.Library (>= 2.0)
NUnit (3.13.2)
Runfiles (0.12)
System.Buffers (4.5.1) - restriction: || (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp3.1)) (== netstandard2.0)
System.Buffers (4.5.1) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Diagnostics.EventLog (7.0)
System.Security.Principal.Windows (>= 5.0) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Diagnostics.Tools (4.3)
Expand All @@ -61,7 +61,7 @@ NUGET
System.Buffers (>= 4.5.1) - restriction: || (&& (== net7.0) (>= monotouch)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp2.0)) (&& (== net7.0) (< netstandard1.1)) (&& (== net7.0) (< netstandard2.0)) (&& (== net7.0) (>= xamarinios)) (&& (== net7.0) (>= xamarinmac)) (&& (== net7.0) (>= xamarintvos)) (&& (== net7.0) (>= xamarinwatchos)) (== netstandard2.0)
System.Numerics.Vectors (>= 4.4) - restriction: || (&& (== net7.0) (< netcoreapp2.0)) (== netstandard2.0)
System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (&& (== net7.0) (>= monotouch)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp2.0)) (&& (== net7.0) (< netcoreapp2.1)) (&& (== net7.0) (< netstandard1.1)) (&& (== net7.0) (< netstandard2.0)) (&& (== net7.0) (>= uap10.1)) (&& (== net7.0) (>= xamarinios)) (&& (== net7.0) (>= xamarinmac)) (&& (== net7.0) (>= xamarintvos)) (&& (== net7.0) (>= xamarinwatchos)) (== netstandard2.0)
System.Numerics.Vectors (4.5) - restriction: || (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp3.1)) (== netstandard2.0)
System.Numerics.Vectors (4.5) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< netcoreapp2.0)) (== netstandard2.0)
System.Reflection (4.3)
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.NETCore.Targets (>= 1.1)
Expand All @@ -79,7 +79,7 @@ NUGET
System.Runtime (4.3.1)
Microsoft.NETCore.Platforms (>= 1.1.1)
Microsoft.NETCore.Targets (>= 1.1.3)
System.Runtime.CompilerServices.Unsafe (6.0)
System.Runtime.CompilerServices.Unsafe (6.0) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Runtime.Handles (4.3)
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.NETCore.Targets (>= 1.1)
Expand All @@ -100,14 +100,13 @@ NUGET
System.Buffers (>= 4.5.1) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Memory (>= 4.5.5) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Text.Json (6.0.9)
Microsoft.Bcl.AsyncInterfaces (>= 6.0) - restriction: || (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp3.1)) (== netstandard2.0)
System.Buffers (>= 4.5.1) - restriction: || (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp3.1)) (== netstandard2.0)
System.Memory (>= 4.5.4) - restriction: || (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp3.1)) (== netstandard2.0)
System.Numerics.Vectors (>= 4.5) - restriction: || (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp3.1)) (== netstandard2.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0)
System.Text.Encodings.Web (>= 6.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp3.1)) (== netstandard2.0)
System.Text.Json (8.0.4)
Microsoft.Bcl.AsyncInterfaces (>= 8.0) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Buffers (>= 4.5.1) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Memory (>= 4.5.5) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Text.Encodings.Web (>= 8.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (&& (== net7.0) (>= net462)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Threading.Tasks (4.3)
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.NETCore.Targets (>= 1.1)
Expand Down
4 changes: 2 additions & 2 deletions dotnet/paket.nuget.bzl

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions dotnet/src/support/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load(
"//dotnet:defs.bzl",
"csharp_library",
"framework",
"generated_assembly_info",
"nuget_pack",
)
Expand Down Expand Up @@ -43,8 +42,7 @@ csharp_library(
"//dotnet:__subpackages__",
],
deps = [
"//dotnet/src/webdriver",
framework("nuget", "NETStandard.Library"),
"//dotnet/src/webdriver:webdriver-netstandard2.0",
],
)

Expand Down Expand Up @@ -83,8 +81,7 @@ csharp_library(
"//dotnet:__subpackages__",
],
deps = [
"//dotnet/src/webdriver:webdriver-strongnamed",
framework("nuget", "NETStandard.Library"),
"//dotnet/src/webdriver:webdriver-netstandard2.0-strongnamed",
],
)

Expand Down
76 changes: 68 additions & 8 deletions dotnet/src/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ generated_assembly_info(
)

csharp_library(
name = "webdriver",
name = "webdriver-netstandard2.0",
srcs = [
":assembly-info",
] + glob([
Expand All @@ -36,7 +36,7 @@ csharp_library(
internals_visible_to = [
"WebDriver.Common.Tests",
],
langversion = "10.0",
langversion = "12.0",
resources = [
"//javascript/atoms/fragments:find-elements.js",
"//javascript/atoms/fragments:is-displayed.js",
Expand All @@ -52,20 +52,50 @@ csharp_library(
],
deps = [
framework("nuget", "NETStandard.Library"),
framework("nuget", "Newtonsoft.Json"),
framework("nuget", "System.Memory"),
framework("nuget", "System.Text.Json"),
],
)

csharp_library(
name = "webdriver-strongnamed",
name = "webdriver-net8.0",
srcs = [
":assembly-info",
] + glob([
"**/*.cs",
]) + devtools_version_targets(),
out = "WebDriver",
internals_visible_to = [
"WebDriver.Common.Tests",
],
langversion = "12.0",
resources = [
"//javascript/atoms/fragments:find-elements.js",
"//javascript/atoms/fragments:is-displayed.js",
"//javascript/cdp-support:mutation-listener.js",
"//javascript/webdriver/atoms:get-attribute.js",
"//third_party/js/selenium:webdriver_json",
],
target_frameworks = [
"net8.0",
],
visibility = [
"//dotnet:__subpackages__",
],
deps = [
],
)

csharp_library(
name = "webdriver-netstandard2.0-strongnamed",
srcs = [
":assembly-info",
] + glob([
"**/*.cs",
]) + devtools_version_targets(),
out = "WebDriver.StrongNamed",
keyfile = "//dotnet:WebDriver.snk",
langversion = "10.0",
langversion = "12.0",
resources = [
"//javascript/atoms/fragments:find-elements.js",
"//javascript/atoms/fragments:is-displayed.js",
Expand All @@ -81,7 +111,35 @@ csharp_library(
],
deps = [
framework("nuget", "NETStandard.Library"),
framework("nuget", "Newtonsoft.Json"),
framework("nuget", "System.Memory"),
framework("nuget", "System.Text.Json"),
],
)

csharp_library(
name = "webdriver-net8.0-strongnamed",
srcs = [
":assembly-info",
] + glob([
"**/*.cs",
]) + devtools_version_targets(),
out = "WebDriver.StrongNamed",
keyfile = "//dotnet:WebDriver.snk",
langversion = "12.0",
resources = [
"//javascript/atoms/fragments:find-elements.js",
"//javascript/atoms/fragments:is-displayed.js",
"//javascript/cdp-support:mutation-listener.js",
"//javascript/webdriver/atoms:get-attribute.js",
"//third_party/js/selenium:webdriver_json",
],
target_frameworks = [
"net8.0",
],
visibility = [
"//dotnet:__subpackages__",
],
deps = [
],
)

Expand Down Expand Up @@ -137,7 +195,8 @@ nuget_pack(
},
id = "Selenium.WebDriver",
libs = {
":webdriver": "WebDriver",
":webdriver-net8.0": "WebDriver",
":webdriver-netstandard2.0": "WebDriver",
},
nuspec_template = "WebDriver.nuspec",
tags = [
Expand All @@ -162,7 +221,8 @@ nuget_pack(
},
id = "Selenium.WebDriver.StrongNamed",
libs = {
":webdriver-strongnamed": "WebDriver.StrongNamed",
":webdriver-net8.0-strongnamed": "WebDriver.StrongNamed",
":webdriver-netstandard2.0-strongnamed": "WebDriver.StrongNamed",
},
nuspec_template = "WebDriver.StrongNamed.nuspec",
property_group_vars = {
Expand Down
14 changes: 8 additions & 6 deletions dotnet/src/webdriver/Chromium/ChromiumNetworkConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
// limitations under the License.
// </copyright>

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OpenQA.Selenium.Chromium
{
/// <summary>
/// Provides manipulation of getting and setting network conditions from Chromium.
/// </summary>
[JsonObject(MemberSerialization.OptIn)]
public class ChromiumNetworkConditions
{
private bool offline;
Expand All @@ -36,7 +35,7 @@ public class ChromiumNetworkConditions
/// <summary>
/// Gets or sets a value indicating whether the network is offline. Defaults to <see langword="false"/>.
/// </summary>
[JsonProperty("offline")]
[JsonPropertyName("offline")]
public bool IsOffline
{
get { return this.offline; }
Expand All @@ -46,6 +45,7 @@ public bool IsOffline
/// <summary>
/// Gets or sets the simulated latency of the connection. Typically given in milliseconds.
/// </summary>
[JsonIgnore]
public TimeSpan Latency
{
get { return this.latency; }
Expand All @@ -55,7 +55,7 @@ public TimeSpan Latency
/// <summary>
/// Gets or sets the throughput of the network connection in bytes/second for downloading.
/// </summary>
[JsonProperty("download_throughput")]
[JsonPropertyName("download_throughput")]
public long DownloadThroughput
{
get { return this.downloadThroughput; }
Expand All @@ -73,7 +73,7 @@ public long DownloadThroughput
/// <summary>
/// Gets or sets the throughput of the network connection in bytes/second for uploading.
/// </summary>
[JsonProperty("upload_throughput")]
[JsonPropertyName("upload_throughput")]
public long UploadThroughput
{
get { return this.uploadThroughput; }
Expand All @@ -88,7 +88,9 @@ public long UploadThroughput
}
}

[JsonProperty("latency", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("latency")]
[JsonInclude]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
internal long? SerializableLatency
nvborisenko marked this conversation as resolved.
Show resolved Hide resolved
{
get
Expand Down
18 changes: 12 additions & 6 deletions dotnet/src/webdriver/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
// limitations under the License.
// </copyright>

using Newtonsoft.Json;
using OpenQA.Selenium.Internal;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace OpenQA.Selenium
{
Expand All @@ -27,6 +28,11 @@ namespace OpenQA.Selenium
/// </summary>
public class Command
{
private readonly static JsonSerializerOptions s_jsonSerializerOptions = new()
{
Converters = { new ResponseValueJsonConverter() }
};

private SessionId commandSessionId;
private string commandName;
private Dictionary<string, object> commandParameters = new Dictionary<string, object>();
Expand Down Expand Up @@ -61,7 +67,7 @@ public Command(SessionId sessionId, string name, Dictionary<string, object> para
/// <summary>
/// Gets the SessionID of the command
/// </summary>
[JsonProperty("sessionId")]
[JsonPropertyName("sessionId")]
public SessionId SessionId
{
get { return this.commandSessionId; }
Expand All @@ -70,7 +76,7 @@ public SessionId SessionId
/// <summary>
/// Gets the command name
/// </summary>
[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name
{
get { return this.commandName; }
Expand All @@ -79,7 +85,7 @@ public string Name
/// <summary>
/// Gets the parameters of the command
/// </summary>
[JsonProperty("parameters")]
[JsonPropertyName("parameters")]
public Dictionary<string, object> Parameters
{
get { return this.commandParameters; }
Expand All @@ -95,7 +101,7 @@ public string ParametersAsJsonString
string parametersString = string.Empty;
if (this.commandParameters != null && this.commandParameters.Count > 0)
{
parametersString = JsonConvert.SerializeObject(this.commandParameters);
parametersString = JsonSerializer.Serialize(this.commandParameters);
}

if (string.IsNullOrEmpty(parametersString))
Expand Down Expand Up @@ -123,7 +129,7 @@ public override string ToString()
/// <returns>A <see cref="Dictionary{K, V}"/> with a string keys, and an object value. </returns>
private static Dictionary<string, object> ConvertParametersFromJson(string value)
{
Dictionary<string, object> parameters = JsonConvert.DeserializeObject<Dictionary<string, object>>(value, new ResponseValueJsonConverter());
Dictionary<string, object> parameters = JsonSerializer.Deserialize<Dictionary<string, object>>(value, s_jsonSerializerOptions);
return parameters;
}
}
Expand Down
Loading
Loading