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

Merged
merged 4 commits into from
Mar 31, 2025

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

    Copy link
    Member

    @nvborisenko nvborisenko left a comment

    Choose a reason for hiding this comment

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

    Approved. I think this PR is still actual, so just actualize it and move forward. Thank you!

    @RenderMichael
    Copy link
    Contributor Author

    Test failures are unrelated:

    //dotnet/test/common:BiDi/Network/NetworkEventsTest-firefox
    //java/test/org/openqa/selenium/mobile:NetworkConnectionTest
    //java/test/org/openqa/selenium/remote:RemoteWebDriverScreenshotTest
    //java/test/org/openqa/selenium/remote:RemoteWebDriverScreenshotTest-firefox-beta
    //rb/spec/integration/selenium/webdriver:network-firefox-beta-bidi
    //rb/spec/integration/selenium/webdriver:network-firefox-bidi

    @RenderMichael RenderMichael merged commit ee17b37 into SeleniumHQ:trunk Mar 31, 2025
    10 checks passed
    @RenderMichael RenderMichael deleted the dotnet-execute branch March 31, 2025 15:20
    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