diff --git a/dotnet/src/webdriver/DefaultFileDetector.cs b/dotnet/src/webdriver/DefaultFileDetector.cs index 927d7ada27e6c..4f21649d1311e 100644 --- a/dotnet/src/webdriver/DefaultFileDetector.cs +++ b/dotnet/src/webdriver/DefaultFileDetector.cs @@ -17,6 +17,10 @@ // under the License. // +using System.Diagnostics.CodeAnalysis; + +#nullable enable + namespace OpenQA.Selenium { /// @@ -31,7 +35,7 @@ public class DefaultFileDetector : IFileDetector /// /// The sequence to test for file existence. /// This method always returns in this implementation. - public bool IsFile(string keySequence) + public bool IsFile([NotNullWhen(true)] string? keySequence) { return false; } diff --git a/dotnet/src/webdriver/DetachedShadowRootException.cs b/dotnet/src/webdriver/DetachedShadowRootException.cs index 0c2a8bfd3fd9d..ae45207be9c2a 100644 --- a/dotnet/src/webdriver/DetachedShadowRootException.cs +++ b/dotnet/src/webdriver/DetachedShadowRootException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public DetachedShadowRootException() /// a specified error message. /// /// The message that describes the error. - public DetachedShadowRootException(string message) + public DetachedShadowRootException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public DetachedShadowRootException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public DetachedShadowRootException(string message, Exception innerException) + public DetachedShadowRootException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/DevTools/CommandResponseException.cs b/dotnet/src/webdriver/DevTools/CommandResponseException.cs index 580a70bbe8b41..9a292804b885f 100644 --- a/dotnet/src/webdriver/DevTools/CommandResponseException.cs +++ b/dotnet/src/webdriver/DevTools/CommandResponseException.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium.DevTools { /// @@ -39,7 +41,7 @@ public CommandResponseException() /// Initializes a new instance of the class with the specified message. /// /// The message of the exception. - public CommandResponseException(string message) + public CommandResponseException(string? message) : base(message) { } @@ -49,7 +51,7 @@ public CommandResponseException(string message) /// /// The message of the exception. /// The inner exception for this exception. - public CommandResponseException(string message, Exception innerException) + public CommandResponseException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/DriverServiceNotFoundException.cs b/dotnet/src/webdriver/DriverServiceNotFoundException.cs index 0941959d50d6b..2afe507aa99d0 100644 --- a/dotnet/src/webdriver/DriverServiceNotFoundException.cs +++ b/dotnet/src/webdriver/DriverServiceNotFoundException.cs @@ -18,12 +18,13 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { /// - /// The exception that is thrown when an element is not visible. + /// The exception that is thrown when the driver service is not available. /// [Serializable] public class DriverServiceNotFoundException : WebDriverException @@ -41,7 +42,7 @@ public DriverServiceNotFoundException() /// a specified error message. /// /// The message that describes the error. - public DriverServiceNotFoundException(string message) + public DriverServiceNotFoundException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public DriverServiceNotFoundException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public DriverServiceNotFoundException(string message, Exception innerException) + public DriverServiceNotFoundException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/ElementClickInterceptedException.cs b/dotnet/src/webdriver/ElementClickInterceptedException.cs index 445abd0d1a5e6..5f76374650a01 100644 --- a/dotnet/src/webdriver/ElementClickInterceptedException.cs +++ b/dotnet/src/webdriver/ElementClickInterceptedException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public ElementClickInterceptedException() /// a specified error message. /// /// The message that describes the error. - public ElementClickInterceptedException(string message) + public ElementClickInterceptedException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public ElementClickInterceptedException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public ElementClickInterceptedException(string message, Exception innerException) + public ElementClickInterceptedException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/ElementNotInteractableException.cs b/dotnet/src/webdriver/ElementNotInteractableException.cs index 86a304f7ff5fc..ec458b4233c85 100644 --- a/dotnet/src/webdriver/ElementNotInteractableException.cs +++ b/dotnet/src/webdriver/ElementNotInteractableException.cs @@ -18,12 +18,13 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { /// - /// The exception that is thrown when an element is not visible. + /// The exception that is thrown when an element is not interactable. /// [Serializable] public class ElementNotInteractableException : InvalidElementStateException @@ -41,7 +42,7 @@ public ElementNotInteractableException() /// a specified error message. /// /// The message that describes the error. - public ElementNotInteractableException(string message) + public ElementNotInteractableException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public ElementNotInteractableException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public ElementNotInteractableException(string message, Exception innerException) + public ElementNotInteractableException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/ElementNotSelectableException.cs b/dotnet/src/webdriver/ElementNotSelectableException.cs index 37a5c91dcb702..7734e883bb222 100644 --- a/dotnet/src/webdriver/ElementNotSelectableException.cs +++ b/dotnet/src/webdriver/ElementNotSelectableException.cs @@ -18,12 +18,13 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { /// - /// The exception that is thrown when an element is not visible. + /// The exception that is thrown when an element is not selectable. /// [Serializable] public class ElementNotSelectableException : InvalidElementStateException @@ -41,7 +42,7 @@ public ElementNotSelectableException() /// a specified error message. /// /// The message that describes the error. - public ElementNotSelectableException(string message) + public ElementNotSelectableException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public ElementNotSelectableException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public ElementNotSelectableException(string message, Exception innerException) + public ElementNotSelectableException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/ElementNotVisibleException.cs b/dotnet/src/webdriver/ElementNotVisibleException.cs index 6db344ed92828..f05ad905afe37 100644 --- a/dotnet/src/webdriver/ElementNotVisibleException.cs +++ b/dotnet/src/webdriver/ElementNotVisibleException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public ElementNotVisibleException() /// a specified error message. /// /// The message that describes the error. - public ElementNotVisibleException(string message) + public ElementNotVisibleException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public ElementNotVisibleException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public ElementNotVisibleException(string message, Exception innerException) + public ElementNotVisibleException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/ErrorResponse.cs b/dotnet/src/webdriver/ErrorResponse.cs index e8143e8a956ab..2d56cfe04ce99 100644 --- a/dotnet/src/webdriver/ErrorResponse.cs +++ b/dotnet/src/webdriver/ErrorResponse.cs @@ -19,6 +19,8 @@ using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium { /// @@ -26,11 +28,6 @@ namespace OpenQA.Selenium /// public class ErrorResponse { - private StackTraceElement[] stackTrace; - private string message = string.Empty; - private string className = string.Empty; - private string screenshot = string.Empty; - /// /// Initializes a new instance of the class. /// @@ -43,58 +40,45 @@ public ErrorResponse() /// /// A containing names and values of /// the properties of this . - public ErrorResponse(Dictionary responseValue) + public ErrorResponse(Dictionary? responseValue) { if (responseValue != null) { - if (responseValue.ContainsKey("message")) + if (responseValue.TryGetValue("message", out object? messageObj) + && messageObj?.ToString() is string message) { - if (responseValue["message"] != null) - { - this.message = responseValue["message"].ToString(); - } - else - { - this.message = "The error did not contain a message."; - } + this.Message = message; } - - if (responseValue.ContainsKey("screen") && responseValue["screen"] != null) + else { - this.screenshot = responseValue["screen"].ToString(); + this.Message = "The error did not contain a message."; } - if (responseValue.ContainsKey("class") && responseValue["class"] != null) + if (responseValue.TryGetValue("screen", out object? screenObj)) { - this.className = responseValue["class"].ToString(); + this.Screenshot = screenObj?.ToString(); } - if (responseValue.ContainsKey("stackTrace") || responseValue.ContainsKey("stacktrace")) + if (responseValue.TryGetValue("class", out object? classObj)) { - object[] stackTraceArray = null; - - if (responseValue.ContainsKey("stackTrace")) - { - stackTraceArray = responseValue["stackTrace"] as object[]; - } - else if (responseValue.ContainsKey("stacktrace")) - { - stackTraceArray = responseValue["stacktrace"] as object[]; - } + this.ClassName = classObj?.ToString(); + } - if (stackTraceArray != null) + if (responseValue.TryGetValue("stackTrace", out object? stackTraceObj) + || responseValue.TryGetValue("stacktrace", out stackTraceObj)) + { + if (stackTraceObj is object?[] stackTraceArray) { List stackTraceList = new List(); - foreach (object rawStackTraceElement in stackTraceArray) + foreach (object? rawStackTraceElement in stackTraceArray) { - Dictionary elementAsDictionary = rawStackTraceElement as Dictionary; - if (elementAsDictionary != null) + if (rawStackTraceElement is Dictionary elementAsDictionary) { stackTraceList.Add(new StackTraceElement(elementAsDictionary)); } } - this.stackTrace = stackTraceList.ToArray(); + this.StackTrace = stackTraceList.ToArray(); } } } @@ -103,38 +87,22 @@ public ErrorResponse(Dictionary responseValue) /// /// Gets or sets the message from the response /// - public string Message - { - get { return this.message; } - set { this.message = value; } - } + public string Message { get; } = string.Empty; /// /// Gets or sets the class name that threw the error /// - public string ClassName - { - get { return this.className; } - set { this.className = value; } - } + public string? ClassName { get; } + // TODO: (JimEvans) Change this to return an Image. /// /// Gets or sets the screenshot of the error /// - public string Screenshot - { - // TODO: (JimEvans) Change this to return an Image. - get { return this.screenshot; } - set { this.screenshot = value; } - } + public string? Screenshot { get; } /// /// Gets or sets the stack trace of the error /// - public StackTraceElement[] StackTrace - { - get { return this.stackTrace; } - set { this.stackTrace = value; } - } + public StackTraceElement[]? StackTrace { get; } } } diff --git a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs index 3d573dc47a91d..da3061c897d8b 100644 --- a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs +++ b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs @@ -288,6 +288,9 @@ public void SetContext(FirefoxCommandContext context) /// /// Full path of the directory of the add-on to install. /// Whether the add-on is temporary; required for unsigned add-ons. + /// The unique identifier of the installed add-on. + /// If is null or empty. + /// If the directory at does not exist. public string InstallAddOnFromDirectory(string addOnDirectoryToInstall, bool temporary = false) { if (string.IsNullOrEmpty(addOnDirectoryToInstall)) @@ -311,6 +314,12 @@ public string InstallAddOnFromDirectory(string addOnDirectoryToInstall, bool tem /// /// Full path and file name of the add-on to install. /// Whether the add-on is temporary; required for unsigned add-ons. + /// The unique identifier of the installed add-on. + /// + /// If is null or empty. + /// or + /// If the file at does not exist. + /// public string InstallAddOnFromFile(string addOnFileToInstall, bool temporary = false) { if (string.IsNullOrEmpty(addOnFileToInstall)) @@ -334,6 +343,8 @@ public string InstallAddOnFromFile(string addOnFileToInstall, bool temporary = f /// /// The base64-encoded string representation of the add-on binary. /// Whether the add-on is temporary; required for unsigned add-ons. + /// The unique identifier of the installed add-on. + /// If is null or empty. public string InstallAddOn(string base64EncodedAddOn, bool temporary = false) { if (string.IsNullOrEmpty(base64EncodedAddOn)) @@ -354,6 +365,7 @@ public string InstallAddOn(string base64EncodedAddOn, bool temporary = false) /// Uninstalls a Firefox add-on. /// /// The ID of the add-on to uninstall. + /// If is null or empty. public void UninstallAddOn(string addOnId) { if (string.IsNullOrEmpty(addOnId)) diff --git a/dotnet/src/webdriver/IFileDetector.cs b/dotnet/src/webdriver/IFileDetector.cs index 49e6a0387a447..2d48f6c722487 100644 --- a/dotnet/src/webdriver/IFileDetector.cs +++ b/dotnet/src/webdriver/IFileDetector.cs @@ -17,6 +17,10 @@ // under the License. // +using System.Diagnostics.CodeAnalysis; + +#nullable enable + namespace OpenQA.Selenium { /// @@ -31,6 +35,6 @@ public interface IFileDetector /// /// The sequence to test for file existence. /// if the key sequence represents a file; otherwise, . - bool IsFile(string keySequence); + bool IsFile([NotNullWhen(true)] string? keySequence); } } diff --git a/dotnet/src/webdriver/InsecureCertificateException.cs b/dotnet/src/webdriver/InsecureCertificateException.cs index 52644886135af..a232f6b511294 100644 --- a/dotnet/src/webdriver/InsecureCertificateException.cs +++ b/dotnet/src/webdriver/InsecureCertificateException.cs @@ -18,12 +18,13 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { /// - /// The exception that is thrown when a frame is not found. + /// The exception that is thrown when an insecure certificate is used. /// [Serializable] public class InsecureCertificateException : WebDriverException @@ -41,7 +42,7 @@ public InsecureCertificateException() /// a specified error message. /// /// The message that describes the error. - public InsecureCertificateException(string message) + public InsecureCertificateException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public InsecureCertificateException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public InsecureCertificateException(string message, Exception innerException) + public InsecureCertificateException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/Internal/NullableAttributes.cs b/dotnet/src/webdriver/Internal/NullableAttributes.cs new file mode 100644 index 0000000000000..bbb123a0a86e2 --- /dev/null +++ b/dotnet/src/webdriver/Internal/NullableAttributes.cs @@ -0,0 +1,168 @@ +// +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + + +#if !NET8_0_OR_GREATER + +// Following polyfill guidance explained here https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/#targetframeworks +// Original code in https://github.com/dotnet/runtime/blob/419e949d258ecee4c40a460fb09c66d974229623/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs + +namespace System.Diagnostics.CodeAnalysis +{ + /// Specifies that null is allowed as an input even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] + internal sealed class AllowNullAttribute : Attribute + { } + + /// Specifies that null is disallowed as an input even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] + internal sealed class DisallowNullAttribute : Attribute + { } + + /// Specifies that an output may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] + internal sealed class MaybeNullAttribute : Attribute + { } + + /// Specifies that an output will not be null even if the corresponding type allows it. Specifies that an input argument was not null when the call returns. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] + internal sealed class NotNullAttribute : Attribute + { } + + /// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class MaybeNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter may be null. + /// + public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class NotNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter will not be null. + /// + public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that the output will be non-null if the named parameter is non-null. + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] + internal sealed class NotNullIfNotNullAttribute : Attribute + { + /// Initializes the attribute with the associated parameter name. + /// + /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. + /// + public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; + + /// Gets the associated parameter name. + public string ParameterName { get; } + } + + /// Applied to a method that will never return under any circumstance. + [AttributeUsage(AttributeTargets.Method, Inherited = false)] + internal sealed class DoesNotReturnAttribute : Attribute + { } + + /// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class DoesNotReturnIfAttribute : Attribute + { + /// Initializes the attribute with the specified parameter value. + /// + /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to + /// the associated parameter matches this value. + /// + public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; + + /// Gets the condition parameter value. + public bool ParameterValue { get; } + } + + /// Specifies that the method or property will ensure that the listed field and property members have not-null values. + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] + internal sealed class MemberNotNullAttribute : Attribute + { + /// Initializes the attribute with a field or property member. + /// + /// The field or property member that is promised to be not-null. + /// + public MemberNotNullAttribute(string member) => Members = new[] { member }; + + /// Initializes the attribute with the list of field and property members. + /// + /// The list of field and property members that are promised to be not-null. + /// + public MemberNotNullAttribute(params string[] members) => Members = members; + + /// Gets field or property member names. + public string[] Members { get; } + } + + /// Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition. + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] + internal sealed class MemberNotNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition and a field or property member. + /// + /// The return value condition. If the method returns this value, the associated field or property member will not be null. + /// + /// + /// The field or property member that is promised to be not-null. + /// + public MemberNotNullWhenAttribute(bool returnValue, string member) + { + ReturnValue = returnValue; + Members = new[] { member }; + } + + /// Initializes the attribute with the specified return value condition and list of field and property members. + /// + /// The return value condition. If the method returns this value, the associated field and property members will not be null. + /// + /// + /// The list of field and property members that are promised to be not-null. + /// + public MemberNotNullWhenAttribute(bool returnValue, params string[] members) + { + ReturnValue = returnValue; + Members = members; + } + + /// Gets the return value condition. + public bool ReturnValue { get; } + + /// Gets field or property member names. + public string[] Members { get; } + } +} + +#endif diff --git a/dotnet/src/webdriver/InvalidCookieDomainException.cs b/dotnet/src/webdriver/InvalidCookieDomainException.cs index d77b16a9877ad..e5ab10dbc7b93 100644 --- a/dotnet/src/webdriver/InvalidCookieDomainException.cs +++ b/dotnet/src/webdriver/InvalidCookieDomainException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public InvalidCookieDomainException() /// a specified error message. /// /// The message that describes the error. - public InvalidCookieDomainException(string message) + public InvalidCookieDomainException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public InvalidCookieDomainException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public InvalidCookieDomainException(string message, Exception innerException) + public InvalidCookieDomainException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/InvalidElementStateException.cs b/dotnet/src/webdriver/InvalidElementStateException.cs index 2ef4f4529f8be..2f4c9d039e7ea 100644 --- a/dotnet/src/webdriver/InvalidElementStateException.cs +++ b/dotnet/src/webdriver/InvalidElementStateException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public InvalidElementStateException() /// a specified error message. /// /// The message that describes the error. - public InvalidElementStateException(string message) + public InvalidElementStateException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public InvalidElementStateException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public InvalidElementStateException(string message, Exception innerException) + public InvalidElementStateException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/InvalidSelectorException.cs b/dotnet/src/webdriver/InvalidSelectorException.cs index 8afe6301dad93..6d15bfb1af118 100644 --- a/dotnet/src/webdriver/InvalidSelectorException.cs +++ b/dotnet/src/webdriver/InvalidSelectorException.cs @@ -18,12 +18,13 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { /// - /// The exception that is thrown when an element is not visible. + /// The exception that is thrown when an invalid selector is used. /// [Serializable] public class InvalidSelectorException : WebDriverException @@ -46,7 +47,7 @@ public InvalidSelectorException() /// a specified error message. /// /// The message that describes the error. - public InvalidSelectorException(string message) + public InvalidSelectorException(string? message) : base(GetMessage(message)) { } @@ -59,7 +60,7 @@ public InvalidSelectorException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public InvalidSelectorException(string message, Exception innerException) + public InvalidSelectorException(string? message, Exception? innerException) : base(GetMessage(message), innerException) { } @@ -69,9 +70,9 @@ public InvalidSelectorException(string message, Exception innerException) /// /// The original message for exception /// The final message for exception - protected static string GetMessage(string message) + protected static string GetMessage(string? message) { - return message + "; " + supportMsg + supportUrl; + return $"{message}; {supportMsg}{supportUrl}"; } } } diff --git a/dotnet/src/webdriver/JavaScriptException.cs b/dotnet/src/webdriver/JavaScriptException.cs index 1fd58e1543c29..d3dcc0b743b30 100644 --- a/dotnet/src/webdriver/JavaScriptException.cs +++ b/dotnet/src/webdriver/JavaScriptException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public JavaScriptException() /// a specified error message. /// /// The message that describes the error. - public JavaScriptException(string message) + public JavaScriptException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public JavaScriptException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public JavaScriptException(string message, Exception innerException) + public JavaScriptException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/MoveTargetOutOfBoundsException.cs b/dotnet/src/webdriver/MoveTargetOutOfBoundsException.cs index 945858e904238..154d1218f804c 100644 --- a/dotnet/src/webdriver/MoveTargetOutOfBoundsException.cs +++ b/dotnet/src/webdriver/MoveTargetOutOfBoundsException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -42,7 +43,7 @@ public MoveTargetOutOfBoundsException() /// a specified error message. /// /// The message that describes the error. - public MoveTargetOutOfBoundsException(string message) + public MoveTargetOutOfBoundsException(string? message) : base(message) { } @@ -55,7 +56,7 @@ public MoveTargetOutOfBoundsException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public MoveTargetOutOfBoundsException(string message, Exception innerException) + public MoveTargetOutOfBoundsException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/NoAlertPresentException.cs b/dotnet/src/webdriver/NoAlertPresentException.cs index d4e0e3c534c83..f7c3c2b31de95 100644 --- a/dotnet/src/webdriver/NoAlertPresentException.cs +++ b/dotnet/src/webdriver/NoAlertPresentException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public NoAlertPresentException() /// a specified error message. /// /// The message that describes the error. - public NoAlertPresentException(string message) + public NoAlertPresentException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public NoAlertPresentException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public NoAlertPresentException(string message, Exception innerException) + public NoAlertPresentException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/NoSuchDriverException.cs b/dotnet/src/webdriver/NoSuchDriverException.cs index 4a411844d5a79..5964267e7d2e6 100644 --- a/dotnet/src/webdriver/NoSuchDriverException.cs +++ b/dotnet/src/webdriver/NoSuchDriverException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -47,7 +48,7 @@ public NoSuchDriverException() /// a specified error message. /// /// The message that describes the error. - public NoSuchDriverException(string message) + public NoSuchDriverException(string? message) : base(GetMessage(message)) { } @@ -60,7 +61,7 @@ public NoSuchDriverException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public NoSuchDriverException(string message, Exception innerException) + public NoSuchDriverException(string? message, Exception? innerException) : base(GetMessage(message), innerException) { } @@ -70,9 +71,9 @@ public NoSuchDriverException(string message, Exception innerException) /// /// The original message for exception /// The final message for exception - protected static string GetMessage(string message) + protected static string GetMessage(string? message) { - return message + "; " + supportMsg + supportUrl; + return $"{message}; {supportMsg}{supportUrl}"; } } } diff --git a/dotnet/src/webdriver/NoSuchElementException.cs b/dotnet/src/webdriver/NoSuchElementException.cs index 83a1f9780fcf7..a6aa6416c0853 100644 --- a/dotnet/src/webdriver/NoSuchElementException.cs +++ b/dotnet/src/webdriver/NoSuchElementException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -47,7 +48,7 @@ public NoSuchElementException() /// a specified error message. /// /// The message that describes the error. - public NoSuchElementException(string message) + public NoSuchElementException(string? message) : base(GetMessage(message)) { } @@ -60,7 +61,7 @@ public NoSuchElementException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public NoSuchElementException(string message, Exception innerException) + public NoSuchElementException(string? message, Exception? innerException) : base(GetMessage(message), innerException) { } @@ -70,9 +71,9 @@ public NoSuchElementException(string message, Exception innerException) /// /// The original message for exception /// The final message for exception - protected static string GetMessage(string message) + protected static string GetMessage(string? message) { - return message + "; " + supportMsg + supportUrl; + return $"{message}; {supportMsg}{supportUrl}"; } } } diff --git a/dotnet/src/webdriver/NoSuchFrameException.cs b/dotnet/src/webdriver/NoSuchFrameException.cs index 29592622f6b0e..517d4dda1e719 100644 --- a/dotnet/src/webdriver/NoSuchFrameException.cs +++ b/dotnet/src/webdriver/NoSuchFrameException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public NoSuchFrameException() /// a specified error message. /// /// The message that describes the error. - public NoSuchFrameException(string message) + public NoSuchFrameException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public NoSuchFrameException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public NoSuchFrameException(string message, Exception innerException) + public NoSuchFrameException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/NoSuchShadowRootException.cs b/dotnet/src/webdriver/NoSuchShadowRootException.cs index 751c2f2fb50bb..22909b1b3c979 100644 --- a/dotnet/src/webdriver/NoSuchShadowRootException.cs +++ b/dotnet/src/webdriver/NoSuchShadowRootException.cs @@ -18,12 +18,13 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { /// - /// The exception that is thrown when a frame is not found. + /// The exception that is thrown when a shadow root is not found. /// [Serializable] public class NoSuchShadowRootException : NotFoundException @@ -41,7 +42,7 @@ public NoSuchShadowRootException() /// a specified error message. /// /// The message that describes the error. - public NoSuchShadowRootException(string message) + public NoSuchShadowRootException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public NoSuchShadowRootException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public NoSuchShadowRootException(string message, Exception innerException) + public NoSuchShadowRootException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/NoSuchWindowException.cs b/dotnet/src/webdriver/NoSuchWindowException.cs index 5fd9cbfa1c1af..7f1ba8bd6e198 100644 --- a/dotnet/src/webdriver/NoSuchWindowException.cs +++ b/dotnet/src/webdriver/NoSuchWindowException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public NoSuchWindowException() /// a specified error message. /// /// The message that describes the error. - public NoSuchWindowException(string message) + public NoSuchWindowException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public NoSuchWindowException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public NoSuchWindowException(string message, Exception innerException) + public NoSuchWindowException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/NotFoundException.cs b/dotnet/src/webdriver/NotFoundException.cs index a215ba31f48f3..acb2ac1fe79c4 100644 --- a/dotnet/src/webdriver/NotFoundException.cs +++ b/dotnet/src/webdriver/NotFoundException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public NotFoundException() /// a specified error message. /// /// The message that describes the error. - public NotFoundException(string message) + public NotFoundException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public NotFoundException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public NotFoundException(string message, Exception innerException) + public NotFoundException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/Remote/LocalFileDetector.cs b/dotnet/src/webdriver/Remote/LocalFileDetector.cs index 7e23d0676ed7d..ab1539b6aaeed 100644 --- a/dotnet/src/webdriver/Remote/LocalFileDetector.cs +++ b/dotnet/src/webdriver/Remote/LocalFileDetector.cs @@ -17,8 +17,11 @@ // under the License. // +using System.Diagnostics.CodeAnalysis; using System.IO; +#nullable enable + namespace OpenQA.Selenium.Remote { /// @@ -33,7 +36,7 @@ public class LocalFileDetector : IFileDetector /// /// The sequence to test for file existence. /// if the key sequence represents a file; otherwise, . - public bool IsFile(string keySequence) + public bool IsFile([NotNullWhen(true)] string? keySequence) { return File.Exists(keySequence); } diff --git a/dotnet/src/webdriver/StackTraceElement.cs b/dotnet/src/webdriver/StackTraceElement.cs index e16c896764330..457ee0d5a0c99 100644 --- a/dotnet/src/webdriver/StackTraceElement.cs +++ b/dotnet/src/webdriver/StackTraceElement.cs @@ -21,6 +21,8 @@ using System.Globalization; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium { /// @@ -44,32 +46,43 @@ public StackTraceElement() /// Initializes a new instance of the class using the given property values. /// /// A containing the names and values for the properties of this . - public StackTraceElement(Dictionary elementAttributes) + public StackTraceElement(Dictionary? elementAttributes) { if (elementAttributes != null) { - if (elementAttributes.ContainsKey("className") && elementAttributes["className"] != null) + if (elementAttributes.TryGetValue("className", out object? classNameObj)) { - this.className = elementAttributes["className"].ToString(); + string? className = classNameObj?.ToString(); + if (className is not null) + { + this.className = className; + } } - if (elementAttributes.ContainsKey("methodName") && elementAttributes["methodName"] != null) + if (elementAttributes.TryGetValue("methodName", out object? methodNameObj)) { - this.methodName = elementAttributes["methodName"].ToString(); + string? methodName = methodNameObj?.ToString(); + if (methodName is not null) + { + this.methodName = methodName; + } } - if (elementAttributes.ContainsKey("lineNumber")) + if (elementAttributes.TryGetValue("lineNumber", out object? lineNumberObj)) { - int line = 0; - if (int.TryParse(elementAttributes["lineNumber"].ToString(), out line)) + if (int.TryParse(lineNumberObj?.ToString(), out int line)) { this.lineNumber = line; } } - if (elementAttributes.ContainsKey("fileName") && elementAttributes["fileName"] != null) + if (elementAttributes.TryGetValue("fileName", out object? fileNameObj)) { - this.fileName = elementAttributes["fileName"].ToString(); + string? fileName = fileNameObj?.ToString(); + if (fileName is not null) + { + this.fileName = fileName; + } } } } diff --git a/dotnet/src/webdriver/StaleElementReferenceException.cs b/dotnet/src/webdriver/StaleElementReferenceException.cs index 23672a63a33f4..38957f83708b2 100644 --- a/dotnet/src/webdriver/StaleElementReferenceException.cs +++ b/dotnet/src/webdriver/StaleElementReferenceException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -46,7 +47,7 @@ public StaleElementReferenceException() /// a specified error message. /// /// The message that describes the error. - public StaleElementReferenceException(string message) + public StaleElementReferenceException(string? message) : base(GetMessage(message)) { } @@ -59,7 +60,7 @@ public StaleElementReferenceException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public StaleElementReferenceException(string message, Exception innerException) + public StaleElementReferenceException(string? message, Exception? innerException) : base(GetMessage(message), innerException) { } @@ -69,9 +70,9 @@ public StaleElementReferenceException(string message, Exception innerException) /// /// The original message for exception /// The final message for exception - protected static string GetMessage(string message) + protected static string GetMessage(string? message) { - return message + "; " + supportMsg + supportUrl; + return $"{message}; {supportMsg}{supportUrl}"; } } } diff --git a/dotnet/src/webdriver/UnableToSetCookieException.cs b/dotnet/src/webdriver/UnableToSetCookieException.cs index 07463efb2a225..453bab307dc4b 100644 --- a/dotnet/src/webdriver/UnableToSetCookieException.cs +++ b/dotnet/src/webdriver/UnableToSetCookieException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public UnableToSetCookieException() /// a specified error message. /// /// The message that describes the error. - public UnableToSetCookieException(string message) + public UnableToSetCookieException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public UnableToSetCookieException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public UnableToSetCookieException(string message, Exception innerException) + public UnableToSetCookieException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/UnhandledAlertException.cs b/dotnet/src/webdriver/UnhandledAlertException.cs index 78d1c99435b31..bb9fa8c2278f6 100644 --- a/dotnet/src/webdriver/UnhandledAlertException.cs +++ b/dotnet/src/webdriver/UnhandledAlertException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -28,7 +29,10 @@ namespace OpenQA.Selenium [Serializable] public class UnhandledAlertException : WebDriverException { - private string alertText; + /// + /// Gets the text of the unhandled alert. + /// + public string AlertText { get; } = string.Empty; /// /// Initializes a new instance of the class. @@ -57,7 +61,7 @@ public UnhandledAlertException(string message) public UnhandledAlertException(string message, string alertText) : base(message) { - this.alertText = alertText; + this.AlertText = alertText; } /// @@ -72,13 +76,5 @@ public UnhandledAlertException(string message, Exception innerException) : base(message, innerException) { } - - /// - /// Gets the text of the unhandled alert. - /// - public string AlertText - { - get { return this.alertText; } - } } } diff --git a/dotnet/src/webdriver/WebDriverArgumentException.cs b/dotnet/src/webdriver/WebDriverArgumentException.cs index 586fdd991cc18..0832624372495 100644 --- a/dotnet/src/webdriver/WebDriverArgumentException.cs +++ b/dotnet/src/webdriver/WebDriverArgumentException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public WebDriverArgumentException() /// a specified error message. /// /// The message that describes the error. - public WebDriverArgumentException(string message) + public WebDriverArgumentException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public WebDriverArgumentException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public WebDriverArgumentException(string message, Exception innerException) + public WebDriverArgumentException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/WebDriverException.cs b/dotnet/src/webdriver/WebDriverException.cs index 25daccb516076..456c6d6c94206 100644 --- a/dotnet/src/webdriver/WebDriverException.cs +++ b/dotnet/src/webdriver/WebDriverException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -51,7 +52,7 @@ public WebDriverException() /// a specified error message. /// /// The message that describes the error. - public WebDriverException(string message) + public WebDriverException(string? message) : base(message) { } @@ -64,7 +65,7 @@ public WebDriverException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public WebDriverException(string message, Exception innerException) + public WebDriverException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/WebDriverTimeoutException.cs b/dotnet/src/webdriver/WebDriverTimeoutException.cs index 513277beaf436..b7dedbbf0f39f 100644 --- a/dotnet/src/webdriver/WebDriverTimeoutException.cs +++ b/dotnet/src/webdriver/WebDriverTimeoutException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public WebDriverTimeoutException() /// a specified error message. /// /// The message that describes the error. - public WebDriverTimeoutException(string message) + public WebDriverTimeoutException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public WebDriverTimeoutException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public WebDriverTimeoutException(string message, Exception innerException) + public WebDriverTimeoutException(string? message, Exception? innerException) : base(message, innerException) { } diff --git a/dotnet/src/webdriver/XPathLookupException.cs b/dotnet/src/webdriver/XPathLookupException.cs index 6e706c6837b28..f8e633cd1ad43 100644 --- a/dotnet/src/webdriver/XPathLookupException.cs +++ b/dotnet/src/webdriver/XPathLookupException.cs @@ -18,7 +18,8 @@ // using System; -using System.Runtime.Serialization; + +#nullable enable namespace OpenQA.Selenium { @@ -41,7 +42,7 @@ public XPathLookupException() /// a specified error message. /// /// The message that describes the error. - public XPathLookupException(string message) + public XPathLookupException(string? message) : base(message) { } @@ -54,7 +55,7 @@ public XPathLookupException(string message) /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. - public XPathLookupException(string message, Exception innerException) + public XPathLookupException(string? message, Exception? innerException) : base(message, innerException) { }