diff --git a/dotnet/src/webdriver/Chromium/ChromiumOptions.cs b/dotnet/src/webdriver/Chromium/ChromiumOptions.cs index c5992ebfb8f9c..dde139d1077d7 100644 --- a/dotnet/src/webdriver/Chromium/ChromiumOptions.cs +++ b/dotnet/src/webdriver/Chromium/ChromiumOptions.cs @@ -641,9 +641,9 @@ private static Dictionary GeneratePerformanceLoggingPreferencesD return perfLoggingPrefsDictionary; } - private static Dictionary GenerateMobileEmulationSettingsDictionary(ChromiumMobileEmulationDeviceSettings? settings, string? deviceName) + private static Dictionary GenerateMobileEmulationSettingsDictionary(ChromiumMobileEmulationDeviceSettings? settings, string? deviceName) { - Dictionary mobileEmulationSettings = new Dictionary(); + Dictionary mobileEmulationSettings = new Dictionary(); if (!string.IsNullOrEmpty(deviceName)) { diff --git a/dotnet/src/webdriver/DevTools/DevToolsSession.cs b/dotnet/src/webdriver/DevTools/DevToolsSession.cs index aebbc46d9467f..946afa47f0ffa 100644 --- a/dotnet/src/webdriver/DevTools/DevToolsSession.cs +++ b/dotnet/src/webdriver/DevTools/DevToolsSession.cs @@ -125,6 +125,7 @@ public DevToolsSession(string endpointAddress, DevToolsOptions options) /// /// A object containing the version-specific DevTools Protocol domain implementations. /// The version-specific DevTools Protocol domain implementation. + /// If the provided is not the right protocol version which is running. public T GetVersionSpecificDomains() where T : DevToolsSessionDomains { if (this.Domains.VersionSpecificDomains is not T versionSpecificDomains) @@ -146,6 +147,7 @@ public T GetVersionSpecificDomains() where T : DevToolsSessionDomains /// The execution timeout of the command in milliseconds. /// to throw an exception if a response is not received; otherwise, . /// The command response object implementing the interface. + /// If is . public async Task?> SendCommand(TCommand command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true) where TCommand : ICommand { @@ -214,6 +216,7 @@ public T GetVersionSpecificDomains() where T : DevToolsSessionDomains /// The execution timeout of the command in milliseconds. /// to throw an exception if a response is not received; otherwise, . /// The command response object implementing the interface. + /// If is . public async Task SendCommand(TCommand command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true) where TCommand : ICommand where TCommandResponse : ICommandResponse @@ -243,6 +246,7 @@ public T GetVersionSpecificDomains() where T : DevToolsSessionDomains /// The execution timeout of the command in milliseconds. /// to throw an exception if a response is not received; otherwise, . /// The command response object implementing the interface. + /// If is . public async Task SendCommand(string commandName, JsonNode commandParameters, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true) { if (this.attachedTargetId == null) @@ -264,6 +268,7 @@ public T GetVersionSpecificDomains() where T : DevToolsSessionDomains /// The execution timeout of the command in milliseconds. /// to throw an exception if a response is not received; otherwise, . /// The command response object implementing the interface. + /// If is . public async Task SendCommand(string commandName, string? sessionId, JsonNode commandParameters, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true) { millisecondsTimeout ??= Convert.ToInt32(CommandTimeout.TotalMilliseconds); diff --git a/dotnet/src/webdriver/DevTools/DevToolsVersionInfo.cs b/dotnet/src/webdriver/DevTools/DevToolsVersionInfo.cs index 347ded9d45b1b..92ad6170ba8af 100644 --- a/dotnet/src/webdriver/DevTools/DevToolsVersionInfo.cs +++ b/dotnet/src/webdriver/DevTools/DevToolsVersionInfo.cs @@ -21,6 +21,8 @@ using System.Text.Json.Serialization; using System.Text.RegularExpressions; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -33,51 +35,69 @@ public class DevToolsVersionInfo /// [JsonPropertyName("Browser")] [JsonInclude] - public string Browser { get; internal set; } + public string? Browser { get; internal set; } /// /// Gets the browser version without the preceding browser name. /// [JsonIgnore] - public string BrowserVersion => Regex.Match(Browser, ".*/(.*)").Groups[1].Value; + public string BrowserVersion + { + get + { + if (Browser is null) + { + throw new InvalidOperationException("Browser value is null"); + } + + return Regex.Match(Browser, ".*/(.*)").Groups[1].Value; + } + } /// /// Gets the browser major version number without the preceding browser name. /// [JsonIgnore] - public string BrowserMajorVersion => Regex.Match(Browser, ".*/(\\d+)\\..*").Groups[1].Value; + public string BrowserMajorVersion + { + get + { + if (Browser is null) + { + throw new InvalidOperationException("Browser value is null"); + } + + return Regex.Match(Browser, ".*/(\\d+)\\..*").Groups[1].Value; + } + } /// /// Gets the version of the Developer Tools Protocol. /// [JsonPropertyName("Protocol-Version")] [JsonInclude] - public string ProtocolVersion { get; internal set; } + public string? ProtocolVersion { get; internal set; } /// /// Gets the user agent string. /// [JsonPropertyName("User-Agent")] [JsonInclude] - public string UserAgent { get; internal set; } + public string? UserAgent { get; internal set; } /// /// Gets the version string for the V8 script engine in use by this version of the browser. /// [JsonPropertyName("V8-Version")] [JsonInclude] - public string V8Version - { - get; - internal set; - } + public string? V8Version { get; internal set; } /// /// Gets the URL for the WebSocket connection used for communicating via the DevTools Protocol. /// [JsonPropertyName("webSocketDebuggerUrl")] [JsonInclude] - public string WebSocketDebuggerUrl { get; internal set; } + public string? WebSocketDebuggerUrl { get; internal set; } /// /// Gets the version number of the V8 script engine, stripping values other than the version number. @@ -88,8 +108,8 @@ public string V8VersionNumber get { //Get the v8 version - var v8VersionMatch = Regex.Match(V8Version, @"^(\d+)\.(\d+)\.(\d+)(\.\d+.*)?"); - if (v8VersionMatch.Success == false || v8VersionMatch.Groups.Count < 4) + Match? v8VersionMatch = V8Version is null ? null : Regex.Match(V8Version, @"^(\d+)\.(\d+)\.(\d+)(\.\d+.*)?"); + if (v8VersionMatch is null || v8VersionMatch.Success == false || v8VersionMatch.Groups.Count < 4) { throw new InvalidOperationException($"Unable to determine v8 version number from v8 version string ({V8Version})"); } @@ -103,7 +123,7 @@ public string V8VersionNumber /// [JsonPropertyName("WebKit-Version")] [JsonInclude] - public string WebKitVersion { get; internal set; } + public string? WebKitVersion { get; internal set; } /// /// Gets the hash of the version of WebKit, stripping values other than the hash. @@ -114,8 +134,8 @@ public string WebKitVersionHash get { //Get the webkit version hash. - var webkitVersionMatch = Regex.Match(WebKitVersion, @"\s\(@(\b[0-9a-f]{5,40}\b)"); - if (webkitVersionMatch.Success == false || webkitVersionMatch.Groups.Count != 2) + var webkitVersionMatch = WebKitVersion is null ? null : Regex.Match(WebKitVersion, @"\s\(@(\b[0-9a-f]{5,40}\b)"); + if (webkitVersionMatch is null || webkitVersionMatch.Success == false || webkitVersionMatch.Groups.Count != 2) { throw new InvalidOperationException($"Unable to determine webkit version hash from webkit version string ({WebKitVersion})"); } diff --git a/dotnet/src/webdriver/DevTools/ICommand.cs b/dotnet/src/webdriver/DevTools/ICommand.cs index 30dfcb7fb35cf..2d9908cb67248 100644 --- a/dotnet/src/webdriver/DevTools/ICommand.cs +++ b/dotnet/src/webdriver/DevTools/ICommand.cs @@ -17,6 +17,8 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -27,24 +29,17 @@ public interface ICommand /// /// Gets the name of the command. /// - string CommandName - { - get; - } + string CommandName { get; } } /// /// Represents a response to a command submitted by the DevTools Remote Interface /// - public interface ICommandResponse - { - } + public interface ICommandResponse; /// /// Represents a response to a command submitted by the DevTools Remote Interface /// public interface ICommandResponse : ICommandResponse - where T : ICommand - { - } + where T : ICommand; } diff --git a/dotnet/src/webdriver/DevTools/IDevTools.cs b/dotnet/src/webdriver/DevTools/IDevTools.cs index b720b5d1e9222..aefcb807316cd 100644 --- a/dotnet/src/webdriver/DevTools/IDevTools.cs +++ b/dotnet/src/webdriver/DevTools/IDevTools.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -42,6 +44,7 @@ public interface IDevTools /// /// The options for the DevToolsSession to use. /// The active session to use to communicate with the Developer Tools debugging protocol. + /// If is . DevToolsSession GetDevToolsSession(DevToolsOptions options); /// diff --git a/dotnet/src/webdriver/DevTools/IDevToolsSession.cs b/dotnet/src/webdriver/DevTools/IDevToolsSession.cs index 9671da3d39780..5f32d87c68564 100644 --- a/dotnet/src/webdriver/DevTools/IDevToolsSession.cs +++ b/dotnet/src/webdriver/DevTools/IDevToolsSession.cs @@ -29,7 +29,7 @@ namespace OpenQA.Selenium.DevTools { /// /// Represents a WebSocket connection to a running DevTools instance that can be used to send - /// commands and recieve events. + /// commands and receive events. /// public interface IDevToolsSession : IDisposable { @@ -50,6 +50,7 @@ public interface IDevToolsSession : IDisposable /// A type specific to the version of Developer Tools with which to communicate. /// /// The version-specific domains for this Developer Tools connection. + /// If the provided is not the right protocol version which is running. T GetVersionSpecificDomains() where T : DevToolsSessionDomains; /// @@ -61,6 +62,7 @@ public interface IDevToolsSession : IDisposable /// The execution timeout of the command in milliseconds. /// to throw an exception if a response is not received; otherwise, . /// The command response object implementing the interface. + /// If is . Task?> SendCommand(TCommand command, CancellationToken cancellationToken, int? millisecondsTimeout, bool throwExceptionIfResponseNotReceived) where TCommand : ICommand; @@ -74,6 +76,7 @@ public interface IDevToolsSession : IDisposable /// The execution timeout of the command in milliseconds. /// to throw an exception if a response is not received; otherwise, . /// The command response object implementing the interface. + /// If is . Task SendCommand(TCommand command, CancellationToken cancellationToken, int? millisecondsTimeout, bool throwExceptionIfResponseNotReceived) where TCommand : ICommand where TCommandResponse : ICommandResponse; @@ -87,6 +90,7 @@ public interface IDevToolsSession : IDisposable /// The execution timeout of the command in milliseconds. /// to throw an exception if a response is not received; otherwise, . /// The command response object implementing the interface. + /// If is . Task SendCommand(string commandName, JsonNode @params, CancellationToken cancellationToken, int? millisecondsTimeout, bool throwExceptionIfResponseNotReceived); } } diff --git a/dotnet/src/webdriver/DevTools/Json/JsonEnumMemberConverter.cs b/dotnet/src/webdriver/DevTools/Json/JsonEnumMemberConverter.cs index 58d23db40579d..7816e21761bcd 100644 --- a/dotnet/src/webdriver/DevTools/Json/JsonEnumMemberConverter.cs +++ b/dotnet/src/webdriver/DevTools/Json/JsonEnumMemberConverter.cs @@ -44,7 +44,7 @@ public JsonEnumMemberConverter() #endif foreach (var value in values) { - var enumMember = type.GetField(value.ToString()); + var enumMember = type.GetField(value.ToString())!; var attr = enumMember.GetCustomAttributes(typeof(EnumMemberAttribute), false) .Cast() .FirstOrDefault(); diff --git a/dotnet/src/webdriver/DevTools/WebSocketConnection.cs b/dotnet/src/webdriver/DevTools/WebSocketConnection.cs index a87300deac7ff..b874c2f0689ed 100644 --- a/dotnet/src/webdriver/DevTools/WebSocketConnection.cs +++ b/dotnet/src/webdriver/DevTools/WebSocketConnection.cs @@ -23,6 +23,8 @@ using System.Threading; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -34,9 +36,7 @@ public class WebSocketConnection private readonly CancellationTokenSource clientTokenSource = new CancellationTokenSource(); private readonly TimeSpan startupTimeout; private readonly TimeSpan shutdownTimeout; - private readonly int bufferSize = 4096; - private Task dataReceiveTask; - private bool isActive = false; + private Task? dataReceiveTask; private ClientWebSocket client = new ClientWebSocket(); private readonly SemaphoreSlim sendMethodSemaphore = new SemaphoreSlim(1, 1); @@ -71,22 +71,22 @@ public WebSocketConnection(TimeSpan startupTimeout, TimeSpan shutdownTimeout) /// /// Occurs when data is received from this connection. /// - public event EventHandler DataReceived; + public event EventHandler? DataReceived; /// /// Occurs when a log message is emitted from this connection. /// - public event EventHandler LogMessage; + public event EventHandler? LogMessage; /// /// Gets a value indicating whether this connection is active. /// - public bool IsActive => this.isActive; + public bool IsActive { get; private set; } = false; /// /// Gets the buffer size for communication used by this connection. /// - public int BufferSize => this.bufferSize; + public int BufferSize { get; } = 4096; /// /// Asynchronously starts communication with the remote end of this connection. @@ -96,6 +96,11 @@ public WebSocketConnection(TimeSpan startupTimeout, TimeSpan shutdownTimeout) /// Thrown when the connection is not established within the startup timeout. public virtual async Task Start(string url) { + if (url is null) + { + throw new ArgumentNullException(nameof(url)); + } + this.Log($"Opening connection to URL {url}", DevToolsSessionLogLevel.Trace); bool connected = false; DateTime timeout = DateTime.Now.Add(this.startupTimeout); @@ -121,7 +126,7 @@ public virtual async Task Start(string url) } this.dataReceiveTask = Task.Run(async () => await this.ReceiveData()); - this.isActive = true; + this.IsActive = true; this.Log($"Connection opened", DevToolsSessionLogLevel.Trace); } @@ -159,6 +164,11 @@ public virtual async Task Stop() /// The task object representing the asynchronous operation. public virtual async Task SendData(string data) { + if (data is null) + { + throw new ArgumentNullException(nameof(data)); + } + ArraySegment messageBuffer = new ArraySegment(Encoding.UTF8.GetBytes(data)); this.Log($"SEND >>> {data}"); @@ -236,7 +246,7 @@ private async Task ReceiveData() try { StringBuilder messageBuilder = new StringBuilder(); - ArraySegment buffer = WebSocket.CreateClientBuffer(this.bufferSize, this.bufferSize); + ArraySegment buffer = WebSocket.CreateClientBuffer(this.BufferSize, this.BufferSize); while (this.client.State != WebSocketState.Closed && !cancellationToken.IsCancellationRequested) { WebSocketReceiveResult receiveResult = await this.client.ReceiveAsync(buffer, cancellationToken).ConfigureAwait(false); @@ -255,7 +265,7 @@ private async Task ReceiveData() // Display text or binary data if (this.client.State == WebSocketState.Open && receiveResult.MessageType != WebSocketMessageType.Close) { - messageBuilder.Append(Encoding.UTF8.GetString(buffer.Array, 0, receiveResult.Count)); + messageBuilder.Append(Encoding.UTF8.GetString(buffer.Array!, 0, receiveResult.Count)); if (receiveResult.EndOfMessage) { string message = messageBuilder.ToString(); @@ -282,7 +292,7 @@ private async Task ReceiveData() } finally { - this.isActive = false; + this.IsActive = false; } } diff --git a/dotnet/src/webdriver/DevTools/v130/V130Network.cs b/dotnet/src/webdriver/DevTools/v130/V130Network.cs index 8d8d7396776f5..c76a972c84c49 100644 --- a/dotnet/src/webdriver/DevTools/v130/V130Network.cs +++ b/dotnet/src/webdriver/DevTools/v130/V130Network.cs @@ -337,57 +337,52 @@ private void OnFetchRequestPaused(object? sender, Fetch.RequestPausedEventArgs e { if (e.ResponseErrorReason == null && e.ResponseStatusCode == null) { - var requestData = new HttpRequestData() - { - RequestId = e.RequestId, - Method = e.Request.Method, - Url = e.Request.Url, - PostData = e.Request.PostData, - Headers = new Dictionary(e.Request.Headers) - }; + var requestData = new HttpRequestData + ( + requestId: e.RequestId, + method: e.Request.Method, + url: e.Request.Url, + postData: e.Request.PostData, + headers: new Dictionary(e.Request.Headers) + ); RequestPausedEventArgs wrapped = new RequestPausedEventArgs(null, requestData); this.OnRequestPaused(wrapped); } else { - var responseData = new HttpResponseData() - { - RequestId = e.RequestId, - Url = e.Request.Url, - ResourceType = e.ResourceType.ToString() - }; - ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(responseData); - - if (e.ResponseStatusCode.HasValue) - { - wrappedResponse.ResponseData.StatusCode = e.ResponseStatusCode.Value; - } + var responseData = new HttpResponseData + ( + requestId: e.RequestId, + url: e.Request.Url, + resourceType: e.ResourceType.ToString(), + statusCode: e.ResponseStatusCode.GetValueOrDefault(), + errorReason: e.ResponseErrorReason?.ToString() + ); if (e.ResponseHeaders != null) { foreach (var header in e.ResponseHeaders) { - if (header.Name.ToLowerInvariant() == "set-cookie") + if (header.Name.Equals("set-cookie", StringComparison.InvariantCultureIgnoreCase)) { - wrappedResponse.ResponseData.CookieHeaders.Add(header.Value); + responseData.CookieHeaders.Add(header.Value); } else { - if (wrappedResponse.ResponseData.Headers.ContainsKey(header.Name)) + if (responseData.Headers.TryGetValue(header.Name, out string? currentHeaderValue)) { - string currentHeaderValue = wrappedResponse.ResponseData.Headers[header.Name]; - wrappedResponse.ResponseData.Headers[header.Name] = currentHeaderValue + ", " + header.Value; + responseData.Headers[header.Name] = currentHeaderValue + ", " + header.Value; } else { - wrappedResponse.ResponseData.Headers.Add(header.Name, header.Value); + responseData.Headers.Add(header.Name, header.Value); } } } } - this.OnResponsePaused(wrappedResponse); + this.OnResponsePaused(new ResponsePausedEventArgs(responseData)); } } } diff --git a/dotnet/src/webdriver/DevTools/v131/V131Network.cs b/dotnet/src/webdriver/DevTools/v131/V131Network.cs index a8c5e2447c9b8..a634125e6d021 100644 --- a/dotnet/src/webdriver/DevTools/v131/V131Network.cs +++ b/dotnet/src/webdriver/DevTools/v131/V131Network.cs @@ -337,57 +337,52 @@ private void OnFetchRequestPaused(object? sender, Fetch.RequestPausedEventArgs e { if (e.ResponseErrorReason == null && e.ResponseStatusCode == null) { - var requestData = new HttpRequestData() - { - RequestId = e.RequestId, - Method = e.Request.Method, - Url = e.Request.Url, - PostData = e.Request.PostData, - Headers = new Dictionary(e.Request.Headers) - }; + var requestData = new HttpRequestData + ( + requestId: e.RequestId, + method: e.Request.Method, + url: e.Request.Url, + postData: e.Request.PostData, + headers: new Dictionary(e.Request.Headers) + ); RequestPausedEventArgs wrapped = new RequestPausedEventArgs(null, requestData); this.OnRequestPaused(wrapped); } else { - var responseData = new HttpResponseData() - { - RequestId = e.RequestId, - Url = e.Request.Url, - ResourceType = e.ResourceType.ToString() - }; - ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(responseData); - - if (e.ResponseStatusCode.HasValue) - { - wrappedResponse.ResponseData.StatusCode = e.ResponseStatusCode.Value; - } + var responseData = new HttpResponseData + ( + requestId: e.RequestId, + url: e.Request.Url, + resourceType: e.ResourceType.ToString(), + statusCode: e.ResponseStatusCode.GetValueOrDefault(), + errorReason: e.ResponseErrorReason?.ToString() + ); if (e.ResponseHeaders != null) { foreach (var header in e.ResponseHeaders) { - if (header.Name.ToLowerInvariant() == "set-cookie") + if (header.Name.Equals("set-cookie", StringComparison.InvariantCultureIgnoreCase)) { - wrappedResponse.ResponseData.CookieHeaders.Add(header.Value); + responseData.CookieHeaders.Add(header.Value); } else { - if (wrappedResponse.ResponseData.Headers.ContainsKey(header.Name)) + if (responseData.Headers.TryGetValue(header.Name, out string? currentHeaderValue)) { - string currentHeaderValue = wrappedResponse.ResponseData.Headers[header.Name]; - wrappedResponse.ResponseData.Headers[header.Name] = currentHeaderValue + ", " + header.Value; + responseData.Headers[header.Name] = currentHeaderValue + ", " + header.Value; } else { - wrappedResponse.ResponseData.Headers.Add(header.Name, header.Value); + responseData.Headers.Add(header.Name, header.Value); } } } } - this.OnResponsePaused(wrappedResponse); + this.OnResponsePaused(new ResponsePausedEventArgs(responseData)); } } } diff --git a/dotnet/src/webdriver/DevTools/v132/V132Network.cs b/dotnet/src/webdriver/DevTools/v132/V132Network.cs index 629a91a018cfb..d5b66f4d4f58c 100644 --- a/dotnet/src/webdriver/DevTools/v132/V132Network.cs +++ b/dotnet/src/webdriver/DevTools/v132/V132Network.cs @@ -337,57 +337,52 @@ private void OnFetchRequestPaused(object? sender, Fetch.RequestPausedEventArgs e { if (e.ResponseErrorReason == null && e.ResponseStatusCode == null) { - var requestData = new HttpRequestData() - { - RequestId = e.RequestId, - Method = e.Request.Method, - Url = e.Request.Url, - PostData = e.Request.PostData, - Headers = new Dictionary(e.Request.Headers) - }; + var requestData = new HttpRequestData + ( + requestId: e.RequestId, + method: e.Request.Method, + url: e.Request.Url, + postData: e.Request.PostData, + headers: new Dictionary(e.Request.Headers) + ); RequestPausedEventArgs wrapped = new RequestPausedEventArgs(null, requestData); this.OnRequestPaused(wrapped); } else { - var responseData = new HttpResponseData() - { - RequestId = e.RequestId, - Url = e.Request.Url, - ResourceType = e.ResourceType.ToString() - }; - ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(responseData); - - if (e.ResponseStatusCode.HasValue) - { - wrappedResponse.ResponseData.StatusCode = e.ResponseStatusCode.Value; - } + var responseData = new HttpResponseData + ( + requestId: e.RequestId, + url: e.Request.Url, + resourceType: e.ResourceType.ToString(), + statusCode: e.ResponseStatusCode.GetValueOrDefault(), + errorReason: e.ResponseErrorReason?.ToString() + ); if (e.ResponseHeaders != null) { foreach (var header in e.ResponseHeaders) { - if (header.Name.ToLowerInvariant() == "set-cookie") + if (header.Name.Equals("set-cookie", StringComparison.InvariantCultureIgnoreCase)) { - wrappedResponse.ResponseData.CookieHeaders.Add(header.Value); + responseData.CookieHeaders.Add(header.Value); } else { - if (wrappedResponse.ResponseData.Headers.ContainsKey(header.Name)) + if (responseData.Headers.TryGetValue(header.Name, out string? currentHeaderValue)) { - string currentHeaderValue = wrappedResponse.ResponseData.Headers[header.Name]; - wrappedResponse.ResponseData.Headers[header.Name] = currentHeaderValue + ", " + header.Value; + responseData.Headers[header.Name] = currentHeaderValue + ", " + header.Value; } else { - wrappedResponse.ResponseData.Headers.Add(header.Name, header.Value); + responseData.Headers.Add(header.Name, header.Value); } } } } - this.OnResponsePaused(wrappedResponse); + this.OnResponsePaused(new ResponsePausedEventArgs(responseData)); } } } diff --git a/dotnet/src/webdriver/DevTools/v85/V85Network.cs b/dotnet/src/webdriver/DevTools/v85/V85Network.cs index 8a2e38ff471a5..77e8174b8c720 100644 --- a/dotnet/src/webdriver/DevTools/v85/V85Network.cs +++ b/dotnet/src/webdriver/DevTools/v85/V85Network.cs @@ -334,57 +334,52 @@ private void OnFetchRequestPaused(object? sender, Fetch.RequestPausedEventArgs e { if (e.ResponseErrorReason == null && e.ResponseStatusCode == null) { - var requestData = new HttpRequestData() - { - RequestId = e.RequestId, - Method = e.Request.Method, - Url = e.Request.Url, - PostData = e.Request.PostData, - Headers = new Dictionary(e.Request.Headers) - }; + var requestData = new HttpRequestData + ( + requestId: e.RequestId, + method: e.Request.Method, + url: e.Request.Url, + postData: e.Request.PostData, + headers: new Dictionary(e.Request.Headers) + ); RequestPausedEventArgs wrapped = new RequestPausedEventArgs(null, requestData); this.OnRequestPaused(wrapped); } else { - var responseData = new HttpResponseData() - { - RequestId = e.RequestId, - Url = e.Request.Url, - ResourceType = e.ResourceType.ToString() - }; - ResponsePausedEventArgs wrappedResponse = new ResponsePausedEventArgs(responseData); - - if (e.ResponseStatusCode.HasValue) - { - wrappedResponse.ResponseData.StatusCode = e.ResponseStatusCode.Value; - } + var responseData = new HttpResponseData + ( + requestId: e.RequestId, + url: e.Request.Url, + resourceType: e.ResourceType.ToString(), + statusCode: e.ResponseStatusCode.GetValueOrDefault(), + errorReason: e.ResponseErrorReason?.ToString() + ); if (e.ResponseHeaders != null) { foreach (var header in e.ResponseHeaders) { - if (header.Name.ToLowerInvariant() == "set-cookie") + if (header.Name.Equals("set-cookie", StringComparison.InvariantCultureIgnoreCase)) { - wrappedResponse.ResponseData.CookieHeaders.Add(header.Value); + responseData.CookieHeaders.Add(header.Value); } else { - if (wrappedResponse.ResponseData.Headers.ContainsKey(header.Name)) + if (responseData.Headers.TryGetValue(header.Name, out string? currentHeaderValue)) { - string currentHeaderValue = wrappedResponse.ResponseData.Headers[header.Name]; - wrappedResponse.ResponseData.Headers[header.Name] = currentHeaderValue + ", " + header.Value; + responseData.Headers[header.Name] = currentHeaderValue + ", " + header.Value; } else { - wrappedResponse.ResponseData.Headers.Add(header.Name, header.Value); + responseData.Headers.Add(header.Name, header.Value); } } } } - this.OnResponsePaused(wrappedResponse); + this.OnResponsePaused(new ResponsePausedEventArgs(responseData)); } } } diff --git a/dotnet/src/webdriver/DomMutatedEventArgs.cs b/dotnet/src/webdriver/DomMutatedEventArgs.cs index 3ee853a0c36a4..04577d42c2d9e 100644 --- a/dotnet/src/webdriver/DomMutatedEventArgs.cs +++ b/dotnet/src/webdriver/DomMutatedEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/DomMutationData.cs b/dotnet/src/webdriver/DomMutationData.cs index 0664918af6338..d15e5e36fca46 100644 --- a/dotnet/src/webdriver/DomMutationData.cs +++ b/dotnet/src/webdriver/DomMutationData.cs @@ -19,6 +19,8 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium { /// @@ -31,34 +33,34 @@ public class DomMutationData /// [JsonPropertyName("target")] [JsonInclude] - public string TargetId { get; internal set; } + public string TargetId { get; internal set; } = null!; /// /// Gets the name of the attribute that is changing. /// [JsonPropertyName("name")] [JsonInclude] - public string AttributeName { get; internal set; } + public string AttributeName { get; internal set; } = null!; /// /// Gets the value to which the attribute is being changed. /// [JsonPropertyName("value")] [JsonInclude] - public string AttributeValue { get; internal set; } + public string AttributeValue { get; internal set; } = null!; /// /// Gets the value from which the attribute has been changed. /// [JsonPropertyName("oldValue")] [JsonInclude] - public string AttributeOriginalValue { get; internal set; } + public string AttributeOriginalValue { get; internal set; } = null!; /// /// Stores the element associated with the target ID /// [JsonIgnore] - public IWebElement Element { get; internal set; } + public IWebElement Element { get; internal set; } = null!; // Set internally /// /// Returns a string that represents the current object. diff --git a/dotnet/src/webdriver/DriverCommand.cs b/dotnet/src/webdriver/DriverCommand.cs index 2c8d6bdad2757..6bd32f861d7be 100644 --- a/dotnet/src/webdriver/DriverCommand.cs +++ b/dotnet/src/webdriver/DriverCommand.cs @@ -19,6 +19,8 @@ using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium { /// @@ -117,7 +119,7 @@ public static class DriverCommand public static readonly string FindShadowChildElement = "findShadowChildElement"; /// - /// Represents FindShadosChildElements command + /// Represents FindShadowChildElements command /// public static readonly string FindShadowChildElements = "findShadowChildElements"; @@ -357,6 +359,7 @@ public static class DriverCommand public static readonly string GetLog = "getLog"; // Virtual Authenticator API + // http://w3c.github.io/webauthn#sctn-automation /// /// Represents the AddVirtualAuthenticator command. diff --git a/dotnet/src/webdriver/DriverOptionsMergeResult.cs b/dotnet/src/webdriver/DriverOptionsMergeResult.cs index e01d8adcc8268..734eca812f3ca 100644 --- a/dotnet/src/webdriver/DriverOptionsMergeResult.cs +++ b/dotnet/src/webdriver/DriverOptionsMergeResult.cs @@ -17,6 +17,8 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium.Remote { /// @@ -25,13 +27,13 @@ namespace OpenQA.Selenium.Remote public class DriverOptionsMergeResult { /// - /// Gets or sets a value indicating whether the DriverOptions would conflict when merged with another option + /// Gets or sets a value indicating whether the DriverOptions would conflict when merged with another option. /// public bool IsMergeConflict { get; set; } /// - /// Gets or sets the name of the name of the option that is in conflict. + /// Gets or sets the name of the name of the option that is in conflict, if any. /// - public string MergeConflictOptionName { get; set; } + public string? MergeConflictOptionName { get; set; } } } diff --git a/dotnet/src/webdriver/DriverProcessStartedEventArgs.cs b/dotnet/src/webdriver/DriverProcessStartedEventArgs.cs index 891e83a55d78e..938709cc0bc1c 100644 --- a/dotnet/src/webdriver/DriverProcessStartedEventArgs.cs +++ b/dotnet/src/webdriver/DriverProcessStartedEventArgs.cs @@ -21,6 +21,8 @@ using System.Diagnostics; using System.IO; +#nullable enable + namespace OpenQA.Selenium { /// @@ -28,52 +30,45 @@ namespace OpenQA.Selenium /// public class DriverProcessStartedEventArgs : EventArgs { - private int processId; - private StreamReader standardOutputStreamReader; - private StreamReader standardErrorStreamReader; - /// /// Initializes a new instance of the class. /// /// The object started. + /// If is . public DriverProcessStartedEventArgs(Process driverProcess) { - this.processId = driverProcess.Id; + if (driverProcess is null) + { + throw new ArgumentNullException(nameof(driverProcess)); + } + + this.ProcessId = driverProcess.Id; if (driverProcess.StartInfo.RedirectStandardOutput && !driverProcess.StartInfo.UseShellExecute) { - this.standardOutputStreamReader = driverProcess.StandardOutput; + this.StandardOutputStreamReader = driverProcess.StandardOutput; } if (driverProcess.StartInfo.RedirectStandardError && !driverProcess.StartInfo.UseShellExecute) { - this.standardErrorStreamReader = driverProcess.StandardError; + this.StandardErrorStreamReader = driverProcess.StandardError; } } /// /// Gets the unique ID of the driver executable process. /// - public int ProcessId - { - get { return this.processId; } - } + public int ProcessId { get; } /// /// Gets a object that can be used to read the contents - /// printed to stdout by a driver service process. + /// printed to stdout by a driver service process. /// - public StreamReader StandardOutputStreamReader - { - get { return this.standardOutputStreamReader; } - } + public StreamReader? StandardOutputStreamReader { get; } /// /// Gets a object that can be used to read the contents - /// printed to stderr by a driver service process. + /// printed to stderr by a driver service process. /// - public StreamReader StandardErrorStreamReader - { - get { return standardErrorStreamReader; } - } + public StreamReader? StandardErrorStreamReader { get; } } } diff --git a/dotnet/src/webdriver/DriverProcessStartingEventArgs.cs b/dotnet/src/webdriver/DriverProcessStartingEventArgs.cs index 37e57dbabbfea..ceb3bfea01eb6 100644 --- a/dotnet/src/webdriver/DriverProcessStartingEventArgs.cs +++ b/dotnet/src/webdriver/DriverProcessStartingEventArgs.cs @@ -20,6 +20,8 @@ using System; using System.Diagnostics; +#nullable enable + namespace OpenQA.Selenium { /// @@ -27,25 +29,21 @@ namespace OpenQA.Selenium /// public class DriverProcessStartingEventArgs : EventArgs { - private ProcessStartInfo startInfo; - /// /// Initializes a new instance of the class. /// /// The of the /// driver process to be started. + /// If is . public DriverProcessStartingEventArgs(ProcessStartInfo startInfo) { - this.startInfo = startInfo; + this.DriverServiceProcessStartInfo = startInfo ?? throw new ArgumentNullException(nameof(startInfo)); } /// /// Gets the object with which the /// driver service process will be started. /// - public ProcessStartInfo DriverServiceProcessStartInfo - { - get { return this.startInfo; } - } + public ProcessStartInfo DriverServiceProcessStartInfo { get; } } } diff --git a/dotnet/src/webdriver/HttpRequestData.cs b/dotnet/src/webdriver/HttpRequestData.cs index 89271991cf733..e1f0db6a86e81 100644 --- a/dotnet/src/webdriver/HttpRequestData.cs +++ b/dotnet/src/webdriver/HttpRequestData.cs @@ -19,6 +19,8 @@ using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium { /// @@ -26,6 +28,23 @@ namespace OpenQA.Selenium /// public class HttpRequestData { + /// + /// Initializes a new instance of the type. + /// + /// The method of the HTTP request. + /// The URL of the HTTP request. + /// The POST data of the HTTP request. + /// The headers of the HTTP request. + /// The ID of the HTTP request. + public HttpRequestData(string method, string url, string? postData, Dictionary headers, string requestId) + { + this.Method = method; + this.Url = url; + this.PostData = postData; + this.Headers = headers; + this.RequestId = requestId; + } + /// /// Gets the method of the HTTP request. /// @@ -37,9 +56,9 @@ public class HttpRequestData public string Url { get; set; } /// - /// Gets the POST data of the HTTP request. + /// Gets the POST data of the HTTP request, if any. /// - public string PostData { get; set; } + public string? PostData { get; set; } /// /// Gets the headers of the HTTP request. @@ -49,6 +68,6 @@ public class HttpRequestData /// /// Gets the ID of the HTTP request. /// - public string RequestId { get; internal set; } + public string RequestId { get; } } } diff --git a/dotnet/src/webdriver/HttpResponseContent.cs b/dotnet/src/webdriver/HttpResponseContent.cs index b865acfde1cb5..5898b4144e058 100644 --- a/dotnet/src/webdriver/HttpResponseContent.cs +++ b/dotnet/src/webdriver/HttpResponseContent.cs @@ -17,8 +17,11 @@ // under the License. // +using System; using System.Text; +#nullable enable + namespace OpenQA.Selenium { /// @@ -34,7 +37,7 @@ public class HttpResponseContent /// The byte array representing the content of the response. public HttpResponseContent(byte[] content) { - this.content = content; + this.content = content ?? throw new ArgumentNullException(nameof(content)); } /// diff --git a/dotnet/src/webdriver/HttpResponseData.cs b/dotnet/src/webdriver/HttpResponseData.cs index ba8f7ce98dd49..66dbf9bee5666 100644 --- a/dotnet/src/webdriver/HttpResponseData.cs +++ b/dotnet/src/webdriver/HttpResponseData.cs @@ -18,6 +18,9 @@ // using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +#nullable enable namespace OpenQA.Selenium { @@ -26,8 +29,22 @@ namespace OpenQA.Selenium /// public class HttpResponseData { - private Dictionary headers = new Dictionary(); - private List cookies = new List(); + /// + /// Initializes a new instance of the type. + /// + /// The ID of the request that generated this response. + /// The URL of the HTTP response. + /// The type of resource for this response. + /// The numeric status code of the HTTP response. + /// The reason for an error response. + public HttpResponseData(string requestId, string url, string resourceType, long statusCode, string? errorReason) + { + RequestId = requestId; + Url = url; + ResourceType = resourceType; + StatusCode = statusCode; + ErrorReason = errorReason; + } /// /// Gets or sets the ID of the request that generated this response. @@ -47,22 +64,17 @@ public class HttpResponseData /// /// Gets or sets the body of the HTTP response. /// - public string Body + [DisallowNull] + public string? Body { - get - { - return this.Content?.ReadAsString(); - } - set - { - this.Content = new HttpResponseContent(value); - } + get => this.Content?.ReadAsString(); + set => this.Content = new HttpResponseContent(value); } /// /// Gets or sets the content of the HTTP response. /// - public HttpResponseContent Content { get; set; } + public HttpResponseContent? Content { get; set; } /// /// Gets or sets the type of resource for this response. @@ -72,16 +84,16 @@ public string Body /// /// Gets or sets the reason for an error response. /// - public string ErrorReason { get; set; } + public string? ErrorReason { get; set; } /// /// Gets the headers of the HTTP response. /// - public Dictionary Headers => this.headers; + public Dictionary Headers { get; } = new Dictionary(); /// /// Gets the cookie headers of the HTTP response. /// - public List CookieHeaders => this.cookies; + public List CookieHeaders { get; } = new List(); } } diff --git a/dotnet/src/webdriver/IActionExecutor.cs b/dotnet/src/webdriver/IActionExecutor.cs index fba580aa2c538..a241f0a9f46af 100644 --- a/dotnet/src/webdriver/IActionExecutor.cs +++ b/dotnet/src/webdriver/IActionExecutor.cs @@ -18,8 +18,11 @@ // using OpenQA.Selenium.Interactions; +using System; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium { /// @@ -36,6 +39,8 @@ public interface IActionExecutor /// Performs the specified list of actions with this action executor. /// /// The list of action sequences to perform. + /// If is . + /// If an element in is . void PerformActions(IList actionSequenceList); /// diff --git a/dotnet/src/webdriver/IAllowsFileDetection.cs b/dotnet/src/webdriver/IAllowsFileDetection.cs index 8986c52ccceb9..b36a647675c2c 100644 --- a/dotnet/src/webdriver/IAllowsFileDetection.cs +++ b/dotnet/src/webdriver/IAllowsFileDetection.cs @@ -17,6 +17,10 @@ // under the License. // +using System; + +#nullable enable + namespace OpenQA.Selenium { /// @@ -29,6 +33,7 @@ public interface IAllowsFileDetection /// Gets or sets the responsible for detecting /// sequences of keystrokes representing file paths and names. /// + /// If the value is set to . IFileDetector FileDetector { get; set; } } } diff --git a/dotnet/src/webdriver/IHasCommandExecutor.cs b/dotnet/src/webdriver/IHasCommandExecutor.cs index e9aa61f6f3da1..1487989cc03de 100644 --- a/dotnet/src/webdriver/IHasCommandExecutor.cs +++ b/dotnet/src/webdriver/IHasCommandExecutor.cs @@ -17,6 +17,8 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/ITargetLocator.cs b/dotnet/src/webdriver/ITargetLocator.cs index 68b55610626bb..fd13e6030e2b8 100644 --- a/dotnet/src/webdriver/ITargetLocator.cs +++ b/dotnet/src/webdriver/ITargetLocator.cs @@ -19,6 +19,7 @@ #nullable enable +using OpenQA.Selenium.Internal; using System; namespace OpenQA.Selenium diff --git a/dotnet/src/webdriver/JavaScriptCallbackExecutedEventArgs.cs b/dotnet/src/webdriver/JavaScriptCallbackExecutedEventArgs.cs index aabf783d23540..47a16dd259166 100644 --- a/dotnet/src/webdriver/JavaScriptCallbackExecutedEventArgs.cs +++ b/dotnet/src/webdriver/JavaScriptCallbackExecutedEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/JavaScriptConsoleApiCalledEventArgs.cs b/dotnet/src/webdriver/JavaScriptConsoleApiCalledEventArgs.cs index 391a4cbca7b70..88cf3e0df4491 100644 --- a/dotnet/src/webdriver/JavaScriptConsoleApiCalledEventArgs.cs +++ b/dotnet/src/webdriver/JavaScriptConsoleApiCalledEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium { /// @@ -32,7 +34,7 @@ public class JavaScriptConsoleApiCalledEventArgs : EventArgs /// The content of the message written to the JavaScript console. /// The time stamp of the message written to the JavaScript console. /// The type of message written to the JavaScript console. - public JavaScriptConsoleApiCalledEventArgs(string messageContent, DateTime messageTimeStamp, string messageType) + public JavaScriptConsoleApiCalledEventArgs(string? messageContent, DateTime messageTimeStamp, string messageType) { this.MessageContent = messageContent; this.MessageTimeStamp = messageTimeStamp; @@ -42,7 +44,7 @@ public JavaScriptConsoleApiCalledEventArgs(string messageContent, DateTime messa /// /// Gets or sets the content of the message written to the JavaScript console. /// - public string MessageContent { get; set; } + public string? MessageContent { get; set; } /// /// Gets or sets the time stamp of the message written to the JavaScript console. diff --git a/dotnet/src/webdriver/JavaScriptExceptionThrownEventArgs.cs b/dotnet/src/webdriver/JavaScriptExceptionThrownEventArgs.cs index bf0e1da43fa26..1e1c2434db66e 100644 --- a/dotnet/src/webdriver/JavaScriptExceptionThrownEventArgs.cs +++ b/dotnet/src/webdriver/JavaScriptExceptionThrownEventArgs.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/NetworkManager.cs b/dotnet/src/webdriver/NetworkManager.cs index eae9b433c7cbb..e2863c8c85523 100644 --- a/dotnet/src/webdriver/NetworkManager.cs +++ b/dotnet/src/webdriver/NetworkManager.cs @@ -262,7 +262,7 @@ private async Task OnResponsePaused(object sender, ResponsePausedEventArgs e) // method demands one; however, the only property used by that method is the RequestId property. // It might be better to refactor that method signature to simply pass the request ID, or // alternatively, just pass the response data, which should also contain the request ID anyway. - HttpRequestData requestData = new HttpRequestData() { RequestId = e.ResponseData.RequestId }; + HttpRequestData requestData = new HttpRequestData(null, null, null, null, requestId: e.ResponseData.RequestId); await this.session.Value.Domains.Network.ContinueRequestWithResponse(requestData, handler.ResponseTransformer(e.ResponseData)).ConfigureAwait(false); return; } diff --git a/dotnet/src/webdriver/NetworkRequestSentEventArgs.cs b/dotnet/src/webdriver/NetworkRequestSentEventArgs.cs index 87e6a64a6c1bb..33e43a04ff8b1 100644 --- a/dotnet/src/webdriver/NetworkRequestSentEventArgs.cs +++ b/dotnet/src/webdriver/NetworkRequestSentEventArgs.cs @@ -20,6 +20,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium { /// @@ -27,10 +29,6 @@ namespace OpenQA.Selenium /// public class NetworkRequestSentEventArgs : EventArgs { - private readonly string requestId; - private readonly string requestUrl; - private readonly string requestMethod; - private readonly string requestPostData; private readonly Dictionary requestHeaders = new Dictionary(); /// @@ -39,10 +37,10 @@ public class NetworkRequestSentEventArgs : EventArgs /// The that describes the network request. public NetworkRequestSentEventArgs(HttpRequestData requestData) { - this.requestId = requestData.RequestId; - this.requestUrl = requestData.Url; - this.requestMethod = requestData.Method; - this.requestPostData = requestData.PostData; + this.RequestId = requestData.RequestId; + this.RequestUrl = requestData.Url; + this.RequestMethod = requestData.Method; + this.RequestPostData = requestData.PostData; foreach (KeyValuePair header in requestData.Headers) { this.requestHeaders[header.Key] = header.Value; @@ -52,22 +50,22 @@ public NetworkRequestSentEventArgs(HttpRequestData requestData) /// /// Gets the internal request ID of the network request. /// - public string RequestId => requestId; + public string RequestId { get; } /// /// Gets the URL of the network request. /// - public string RequestUrl => requestUrl; + public string RequestUrl { get; } /// /// Gets the HTTP method of the network request. /// - public string RequestMethod => requestMethod; + public string RequestMethod { get; } /// /// Gets the post data of the network request, if any. /// - public string RequestPostData => requestPostData; + public string? RequestPostData { get; } /// /// Gets the collection of headers associated with the network request. diff --git a/dotnet/src/webdriver/NetworkResponseReceivedEventArgs.cs b/dotnet/src/webdriver/NetworkResponseReceivedEventArgs.cs index 2f4d9318b991f..5710531fa71b7 100644 --- a/dotnet/src/webdriver/NetworkResponseReceivedEventArgs.cs +++ b/dotnet/src/webdriver/NetworkResponseReceivedEventArgs.cs @@ -20,6 +20,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium { /// @@ -27,11 +29,6 @@ namespace OpenQA.Selenium /// public class NetworkResponseReceivedEventArgs : EventArgs { - private readonly string requestId; - private readonly string responseUrl; - private readonly long responseStatusCode; - private readonly HttpResponseContent responseContent; - private readonly string responseResourceType; private readonly Dictionary responseHeaders = new Dictionary(); /// @@ -40,11 +37,11 @@ public class NetworkResponseReceivedEventArgs : EventArgs /// The that describes the network response. public NetworkResponseReceivedEventArgs(HttpResponseData responseData) { - this.requestId = responseData.RequestId; - this.responseUrl = responseData.Url; - this.responseStatusCode = responseData.StatusCode; - this.responseContent = responseData.Content; - this.responseResourceType = responseData.ResourceType; + this.RequestId = responseData.RequestId; + this.ResponseUrl = responseData.Url; + this.ResponseStatusCode = responseData.StatusCode; + this.ResponseContent = responseData.Content; + this.ResponseResourceType = responseData.ResourceType; foreach (KeyValuePair header in responseData.Headers) { this.responseHeaders[header.Key] = header.Value; @@ -54,17 +51,17 @@ public NetworkResponseReceivedEventArgs(HttpResponseData responseData) /// /// Gets the request ID of the network request that generated this response. /// - public string RequestId => this.requestId; + public string RequestId { get; } /// /// Gets the URL of the network response. /// - public string ResponseUrl => this.responseUrl; + public string ResponseUrl { get; } /// /// Gets the HTTP status code of the network response. /// - public long ResponseStatusCode => this.responseStatusCode; + public long ResponseStatusCode { get; } /// /// Gets the body of the network response. @@ -72,17 +69,17 @@ public NetworkResponseReceivedEventArgs(HttpResponseData responseData) /// /// This property is an alias for .ReadAsString() to keep backward compatibility. /// - public string ResponseBody => this.ResponseContent?.ReadAsString(); + public string? ResponseBody => this.ResponseContent?.ReadAsString(); /// - /// Gets the content of the network response. + /// Gets the content of the network response, if any. /// - public HttpResponseContent ResponseContent => this.responseContent; + public HttpResponseContent? ResponseContent { get; } /// /// Gets the type of resource of the network response. /// - public string ResponseResourceType => this.responseResourceType; + public string ResponseResourceType { get; } /// /// Gets the headers associated with this network response. diff --git a/dotnet/src/webdriver/Response.cs b/dotnet/src/webdriver/Response.cs index b313c16513872..afb8b720e2bf0 100644 --- a/dotnet/src/webdriver/Response.cs +++ b/dotnet/src/webdriver/Response.cs @@ -66,9 +66,11 @@ public Response(SessionId? sessionId) /// The WebDriver result status of the response. public Response(string? sessionId, object? value, WebDriverResult status) { +#pragma warning disable CS0618 // Type or member is obsolete this.SessionId = sessionId; this.Value = value; this.Status = status; +#pragma warning restore CS0618 // Type or member is obsolete } ///