Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[dotnet] Annotate nullability on elements and WebDriver #15352

Merged

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Mar 1, 2025

User description

Description

Finishes annotating nullability on WebElement and WebDriver, including their related interfaces IWebElement and IWebDriver. Also annotates interfaces they implement, such as IJavascriptExecutor.

Motivation and Context

Contributes to #14640

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement, Bug fix


Description

  • Annotated nullability for WebElement, WebDriver, and related interfaces.

  • Improved type safety by introducing nullable references.

  • Added exception handling and documentation for null-related scenarios.

  • Refactored code to align with nullable reference types.


Changes walkthrough 📝

Relevant files
Enhancement
12 files
EventFiringWebDriver.cs
Added nullability annotations and refactored script execution methods.
+14/-26 
ChromiumDriver.cs
Updated browser path handling with nullable annotations. 
+1/-1     
Command.cs
Enhanced command parameter handling with nullable annotations.
+5/-5     
CookieJar.cs
Updated cookie handling with nullable annotations.             
+1/-1     
FirefoxDriver.cs
Updated Firefox driver browser path handling with nullable
annotations.
+1/-1     
IJavascriptExecutor.cs
Annotated nullability for JavaScript execution methods.   
+5/-3     
IWebDriver.cs
Enabled nullable reference types for `IWebDriver`.             
+2/-0     
IWebElement.cs
Annotated nullability for IWebElement attribute and property methods.
+5/-3     
RelativeBy.cs
Updated JavaScript execution with nullable annotations.   
+1/-1     
WebDriver.cs
Refactored WebDriver methods with nullable annotations and improved
safety.
+32/-34 
WebElement.cs
Refactored WebElement methods with nullable annotations and improved
safety.
+9/-17   
WebElementFactory.cs
Added exception handling and nullable annotations for element
creation.
+3/-0     
Documentation
1 files
By.cs
Added exception documentation for element finding methods.
+2/-1     
Bug fix
3 files
FirefoxProfile.cs
Added null-forgiving operator for profile directory handling.
+1/-1     
ShadowRoot.cs
Added null-forgiving operator for shadow root element handling.
+1/-1     
TargetLocator.cs
Updated active element and window name handling with null-forgiving
operators.
+2/-2     

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    qodo-merge-pro bot commented Mar 1, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Null Safety

    The GetElementFromResponse method now returns nullable IWebElement but is force-unwrapped with ! operator in several places. Need to validate that null checks are properly handled in all cases.

    internal IWebElement? GetElementFromResponse(Response response)
    {
        if (response.Value is Dictionary<string, object?> elementDictionary)
        {
            return this.elementFactory.CreateElement(elementDictionary);
        }
    
        return null;
    API Change

    Changed Dictionary<string, object> to Dictionary<string, object?> in Command parameters which could affect existing code that assumes non-null values.

    public Command(SessionId? sessionId, string name, Dictionary<string, object?>? parameters)
    {
        this.SessionId = sessionId;
        this.Parameters = parameters ?? new Dictionary<string, object?>();
        this.Name = name ?? throw new ArgumentNullException(nameof(name));
    }

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 1, 2025

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @RenderMichael RenderMichael merged commit 375dcea into SeleniumHQ:trunk Mar 1, 2025
    10 checks passed
    @RenderMichael RenderMichael deleted the nullable-element-and-driver branch March 1, 2025 07:50
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant