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] [bidi] Decouple nested types in Locator #15487

Merged
merged 1 commit into from
Mar 23, 2025

Conversation

nvborisenko
Copy link
Member

@nvborisenko nvborisenko commented Mar 23, 2025

User description

Motivation and Context

Contributes to #15407

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


Description

  • Decoupled nested DTO types into standalone types for better flexibility.

  • Replaced nested types like AccessibilityLocatorValue with independent records.

  • Introduced new standalone types: AccessibilityValue, ContextValue, and MatchType.

  • Improved maintainability and future extensibility of locator-related classes.


Changes walkthrough 📝

Relevant files
Enhancement
Locator.cs
Decoupled nested DTO types into standalone records             

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs

  • Replaced nested DTO types with standalone records.
  • Added AccessibilityValue and ContextValue as independent records.
  • Introduced MatchType enum for InnerTextLocator.
  • Simplified and decoupled locator-related class definitions.
  • +17/-19 

    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

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    15407 - Fully compliant

    Compliant requirements:

    • Decoupled nested DTO types in Locator classes
    • Replaced nested types with standalone types
    • Implemented the specific example of using CssLocator instead of Locator.Css
    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Missing Serialization Attribute

    The new standalone types (AccessibilityValue, ContextValue) and enum (MatchType) may need JsonDerivedType attributes for proper serialization/deserialization, similar to how they were handled in the nested types.

    public enum MatchType
    {
        Full,
        Partial
    }

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Add JSON property mapping

    Update the InnerTextLocator class to use the JsonPropertyName attribute for the
    MatchType property to ensure proper serialization with the BiDi protocol, which
    expects "match" as the property name.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs [38-45]

     public record InnerTextLocator(string Value) : Locator
     {
         public bool? IgnoreCase { get; set; }
     
    +    [JsonPropertyName("match")]
         public MatchType? MatchType { get; set; }
     
         public long? MaxDepth { get; set; }
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion correctly identifies a potential serialization issue with the BiDi protocol. Adding the JsonPropertyName attribute ensures the MatchType property will be properly serialized as "match" in JSON, which is critical for protocol compatibility. This is an important fix that prevents potential runtime errors.

    Medium
    Learned
    best practice
    Initialize nullable properties with meaningful default values to improve code clarity and prevent potential null reference issues

    The InnerTextLocator record has nullable properties without default values.
    Consider initializing these properties with meaningful default values in the
    constructor to improve code clarity and prevent potential null reference issues.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs [38-45]

     public record InnerTextLocator(string Value) : Locator
     {
    -    public bool? IgnoreCase { get; set; }
    +    public bool? IgnoreCase { get; set; } = false;
     
    -    public MatchType? MatchType { get; set; }
    +    public MatchType? MatchType { get; set; } = MatchType.Full;
     
    -    public long? MaxDepth { get; set; }
    +    public long? MaxDepth { get; set; } = null;
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 6
    Low
    • More

    @nvborisenko nvborisenko merged commit 889dee7 into SeleniumHQ:trunk Mar 23, 2025
    10 checks passed
    @nvborisenko nvborisenko deleted the bidi-nested-locator branch March 23, 2025 20:21
    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