Skip to content

Commit

Permalink
Merge branch 'trunk' into metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
VietND96 authored Nov 18, 2024
2 parents ede02c2 + 9054e89 commit ebc1006
Show file tree
Hide file tree
Showing 47 changed files with 753 additions and 286 deletions.
6 changes: 5 additions & 1 deletion dotnet/src/webdriver/DefaultFileDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
// under the License.
// </copyright>

using System.Diagnostics.CodeAnalysis;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
Expand All @@ -31,7 +35,7 @@ public class DefaultFileDetector : IFileDetector
/// </summary>
/// <param name="keySequence">The sequence to test for file existence.</param>
/// <returns>This method always returns <see langword="false"/> in this implementation.</returns>
public bool IsFile(string keySequence)
public bool IsFile([NotNullWhen(true)] string? keySequence)
{
return false;
}
Expand Down
7 changes: 4 additions & 3 deletions dotnet/src/webdriver/DetachedShadowRootException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
Expand All @@ -41,7 +42,7 @@ public DetachedShadowRootException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public DetachedShadowRootException(string message)
public DetachedShadowRootException(string? message)
: base(message)
{
}
Expand All @@ -54,7 +55,7 @@ public DetachedShadowRootException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public DetachedShadowRootException(string message, Exception innerException)
public DetachedShadowRootException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
6 changes: 4 additions & 2 deletions dotnet/src/webdriver/DevTools/CommandResponseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

using System;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
Expand All @@ -39,7 +41,7 @@ public CommandResponseException()
/// Initializes a new instance of the <see cref="CommandResponseException"/> class with the specified message.
/// </summary>
/// <param name="message">The message of the exception.</param>
public CommandResponseException(string message)
public CommandResponseException(string? message)
: base(message)
{
}
Expand All @@ -49,7 +51,7 @@ public CommandResponseException(string message)
/// </summary>
/// <param name="message">The message of the exception.</param>
/// <param name="innerException">The inner exception for this exception.</param>
public CommandResponseException(string message, Exception innerException)
public CommandResponseException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
9 changes: 5 additions & 4 deletions dotnet/src/webdriver/DriverServiceNotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// The exception that is thrown when an element is not visible.
/// The exception that is thrown when the driver service is not available.
/// </summary>
[Serializable]
public class DriverServiceNotFoundException : WebDriverException
Expand All @@ -41,7 +42,7 @@ public DriverServiceNotFoundException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public DriverServiceNotFoundException(string message)
public DriverServiceNotFoundException(string? message)
: base(message)
{
}
Expand All @@ -54,7 +55,7 @@ public DriverServiceNotFoundException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public DriverServiceNotFoundException(string message, Exception innerException)
public DriverServiceNotFoundException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
7 changes: 4 additions & 3 deletions dotnet/src/webdriver/ElementClickInterceptedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
Expand All @@ -41,7 +42,7 @@ public ElementClickInterceptedException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ElementClickInterceptedException(string message)
public ElementClickInterceptedException(string? message)
: base(message)
{
}
Expand All @@ -54,7 +55,7 @@ public ElementClickInterceptedException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public ElementClickInterceptedException(string message, Exception innerException)
public ElementClickInterceptedException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
9 changes: 5 additions & 4 deletions dotnet/src/webdriver/ElementNotInteractableException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// The exception that is thrown when an element is not visible.
/// The exception that is thrown when an element is not interactable.
/// </summary>
[Serializable]
public class ElementNotInteractableException : InvalidElementStateException
Expand All @@ -41,7 +42,7 @@ public ElementNotInteractableException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ElementNotInteractableException(string message)
public ElementNotInteractableException(string? message)
: base(message)
{
}
Expand All @@ -54,7 +55,7 @@ public ElementNotInteractableException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public ElementNotInteractableException(string message, Exception innerException)
public ElementNotInteractableException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
9 changes: 5 additions & 4 deletions dotnet/src/webdriver/ElementNotSelectableException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// The exception that is thrown when an element is not visible.
/// The exception that is thrown when an element is not selectable.
/// </summary>
[Serializable]
public class ElementNotSelectableException : InvalidElementStateException
Expand All @@ -41,7 +42,7 @@ public ElementNotSelectableException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ElementNotSelectableException(string message)
public ElementNotSelectableException(string? message)
: base(message)
{
}
Expand All @@ -54,7 +55,7 @@ public ElementNotSelectableException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public ElementNotSelectableException(string message, Exception innerException)
public ElementNotSelectableException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
7 changes: 4 additions & 3 deletions dotnet/src/webdriver/ElementNotVisibleException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
// </copyright>

using System;
using System.Runtime.Serialization;

#nullable enable

namespace OpenQA.Selenium
{
Expand All @@ -41,7 +42,7 @@ public ElementNotVisibleException()
/// a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ElementNotVisibleException(string message)
public ElementNotVisibleException(string? message)
: base(message)
{
}
Expand All @@ -54,7 +55,7 @@ public ElementNotVisibleException(string message)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public ElementNotVisibleException(string message, Exception innerException)
public ElementNotVisibleException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
82 changes: 25 additions & 57 deletions dotnet/src/webdriver/ErrorResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@

using System.Collections.Generic;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// Provides a way to store errors from a response
/// </summary>
public class ErrorResponse
{
private StackTraceElement[] stackTrace;
private string message = string.Empty;
private string className = string.Empty;
private string screenshot = string.Empty;

/// <summary>
/// Initializes a new instance of the <see cref="ErrorResponse"/> class.
/// </summary>
Expand All @@ -43,58 +40,45 @@ public ErrorResponse()
/// </summary>
/// <param name="responseValue">A <see cref="Dictionary{K, V}"/> containing names and values of
/// the properties of this <see cref="ErrorResponse"/>.</param>
public ErrorResponse(Dictionary<string, object> responseValue)
public ErrorResponse(Dictionary<string, object?>? 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<StackTraceElement> stackTraceList = new List<StackTraceElement>();
foreach (object rawStackTraceElement in stackTraceArray)
foreach (object? rawStackTraceElement in stackTraceArray)
{
Dictionary<string, object> elementAsDictionary = rawStackTraceElement as Dictionary<string, object>;
if (elementAsDictionary != null)
if (rawStackTraceElement is Dictionary<string, object?> elementAsDictionary)
{
stackTraceList.Add(new StackTraceElement(elementAsDictionary));
}
}

this.stackTrace = stackTraceList.ToArray();
this.StackTrace = stackTraceList.ToArray();
}
}
}
Expand All @@ -103,38 +87,22 @@ public ErrorResponse(Dictionary<string, object> responseValue)
/// <summary>
/// Gets or sets the message from the response
/// </summary>
public string Message
{
get { return this.message; }
set { this.message = value; }
}
public string Message { get; } = string.Empty;

/// <summary>
/// Gets or sets the class name that threw the error
/// </summary>
public string ClassName
{
get { return this.className; }
set { this.className = value; }
}
public string? ClassName { get; }

// TODO: (JimEvans) Change this to return an Image.
/// <summary>
/// Gets or sets the screenshot of the error
/// </summary>
public string Screenshot
{
// TODO: (JimEvans) Change this to return an Image.
get { return this.screenshot; }
set { this.screenshot = value; }
}
public string? Screenshot { get; }

/// <summary>
/// Gets or sets the stack trace of the error
/// </summary>
public StackTraceElement[] StackTrace
{
get { return this.stackTrace; }
set { this.stackTrace = value; }
}
public StackTraceElement[]? StackTrace { get; }
}
}
Loading

0 comments on commit ebc1006

Please sign in to comment.