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] Unify protected and internal Execute methods #15233

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Feb 5, 2025

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

protected + internal -> protected internal

Motivation and Context

Less overloads, shorter stack traces, less maintenance.

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

  • Unified InternalExecute and Execute methods into a single protected internal method.

  • Replaced all occurrences of InternalExecute with Execute across multiple classes.

  • Added null checks for constructor parameters in HttpCommandInfo.

  • Simplified and streamlined method calls for better maintainability and reduced stack traces.


Changes walkthrough 📝

Relevant files
Enhancement
10 files
Alert.cs
Replaced `InternalExecute` with `Execute` in alert handling.
+4/-4     
CookieJar.cs
Replaced `InternalExecute` with `Execute` in cookie management.
+5/-5     
Logs.cs
Replaced `InternalExecute` with `Execute` in log retrieval.
+2/-2     
Navigator.cs
Replaced InternalExecuteAsync with ExecuteAsync in navigation methods.
+4/-4     
ShadowRoot.cs
Replaced InternalExecute with Execute in shadow DOM element handling.
+2/-2     
TargetLocator.cs
Replaced InternalExecute with Execute in frame and window switching.
+8/-8     
Timeouts.cs
Replaced `InternalExecute` with `Execute` in timeout management.
+2/-2     
WebDriver.cs
Unified InternalExecute and Execute methods into a single protected
internal method.
+2/-25   
WebElement.cs
Replaced InternalExecute with Execute in element-specific commands.
+1/-1     
Window.cs
Replaced `InternalExecute` with `Execute` in window management.
+7/-7     
Error handling
1 files
HttpCommandInfo.cs
Added null checks for constructor parameters.                       
+3/-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 Feb 5, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    API Change

    The Execute method visibility changed from protected to protected internal. Validate this change does not break any existing code that inherits from WebDriver.

    protected internal virtual Response Execute(string driverCommandToExecute,
        Dictionary<string, object> parameters)
    {
        return Task.Run(() => this.ExecuteAsync(driverCommandToExecute, parameters)).GetAwaiter().GetResult();
    }
    Exception Handling

    New null checks were added to constructor parameters. Verify this change does not affect existing code that may have been passing null values.

    this.ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
    this.Method = method ?? throw new ArgumentNullException(nameof(method));

    Copy link
    Contributor

    qodo-merge-pro bot commented Feb 5, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Improve null parameter validation

    Add null checks for constructor parameters before assigning them to avoid
    potential null reference exceptions later in the code execution.

    dotnet/src/webdriver/HttpCommandInfo.cs [55-58]

     public HttpCommandInfo(string method, string resourcePath)
     {
    -    this.ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
    -    this.Method = method ?? throw new ArgumentNullException(nameof(method));
    +    if (method is null)
    +    {
    +        throw new ArgumentNullException(nameof(method));
    +    }
    +    if (resourcePath is null) 
    +    {
    +        throw new ArgumentNullException(nameof(resourcePath));
    +    }
    +    this.Method = method;
    +    this.ResourcePath = resourcePath;
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 3

    Why: While the suggestion proposes a more explicit null-checking approach, the existing code using null-coalescing operators is equally effective and more concise. The change would only marginally improve code readability.

    3

    @@ -617,7 +594,7 @@ protected virtual Response Execute(string driverCommandToExecute,
    /// <param name="driverCommandToExecute">A <see cref="DriverCommand"/> value representing the command to execute.</param>
    /// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
    /// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
    protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string, object> parameters)
    protected internal virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string, object> parameters)
    Copy link
    Contributor Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    This is actually not a breaking change!
    image

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Copy link
    Member

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    I don't trust.

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    I validated it myself (in the screenshot) and the docs verify this. It's safe!

    Copy link
    Member

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    compile time or at binary level?

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Hmmm, I'm not sure about binary compatibility. Let me do more research.

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    I asked the .NET team, and they said it is not a source or a binary breaking change

    dotnet/roslyn#77157 (reply in thread)

    @@ -617,7 +594,7 @@ protected virtual Response Execute(string driverCommandToExecute,
    /// <param name="driverCommandToExecute">A <see cref="DriverCommand"/> value representing the command to execute.</param>
    /// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
    /// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
    protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string, object> parameters)
    protected internal virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string, object> parameters)
    Copy link
    Member

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    I don't trust.

    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.

    2 participants