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] Make input Origin as not nested #15445

Merged
merged 2 commits into from
Mar 17, 2025

Conversation

nvborisenko
Copy link
Member

@nvborisenko nvborisenko commented Mar 17, 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

  • Refactored nested Origin types to standalone types.

  • Updated JSON serialization logic for new Origin types.

  • Improved code clarity by renaming and restructuring classes.


Changes walkthrough 📝

Relevant files
Enhancement
InputOriginConverter.cs
Update JSON serialization for refactored `Origin` types   

dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs

  • Replaced checks for nested Origin types with standalone types.
  • Updated JSON serialization logic to align with new type structure.
  • Adjusted property serialization for ElementOrigin.
  • +4/-4     
    Origin.cs
    Refactor `Origin` nested types into standalone records     

    dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs

  • Refactored Origin nested types into standalone records.
  • Renamed Viewport, Pointer, and Element to ViewportOrigin,
    PointerOrigin, and ElementOrigin.
  • Adjusted ElementOrigin to include Type property with internal
    visibility.
  • +8/-8     

    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 - Partially compliant

    Compliant requirements:

    • Replace nested DTO types with standalone types
    • Move away from pattern like new Locator.Css("div") to new CssLocator("div")

    Non-compliant requirements:

    • Apply this pattern to all similar types (PR only addresses Origin types)

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

    Property Naming

    The property name in ElementOrigin changed from 'SharedReference' to 'Element', but the serialization still uses 'element' as the property name. Verify this is consistent with other serialization patterns.

    JsonSerializer.Serialize(writer, element.Element, options);

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 17, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add missing JSON property attribute

    The Element property is missing the JsonPropertyName attribute that was present
    in the original code. This might cause serialization issues as the JSON property
    name will default to "Element" instead of "element". Add the attribute to
    maintain compatibility.

    dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs [30-34]

    -public record ElementOrigin(Script.ISharedReference Element) : Origin
    +public record ElementOrigin([property: JsonPropertyName("element")] Script.ISharedReference Element) : Origin
     {
         [JsonInclude]
         internal string Type { get; } = "element";
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: This suggestion correctly identifies a critical issue where the JsonPropertyName attribute was removed during refactoring. Without this attribute, the serialized JSON would use "Element" instead of "element", potentially breaking API compatibility and causing integration issues.

    High
    Learned
    best practice
    Add null parameter validation at the beginning of methods to prevent NullReferenceExceptions and provide clear error messages

    Add null checks for the writer, value, and options parameters at the beginning
    of the method to ensure they are not null before using them. This prevents
    potential NullReferenceExceptions and provides clear error messages.

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs [34-52]

     public override void Write(Utf8JsonWriter writer, Origin value, JsonSerializerOptions options)
     {
    +    ArgumentNullException.ThrowIfNull(writer, nameof(writer));
    +    ArgumentNullException.ThrowIfNull(value, nameof(value));
    +    ArgumentNullException.ThrowIfNull(options, nameof(options));
    +    
         if (value is ViewportOrigin)
         {
             writer.WriteStringValue("viewport");
         }
         else if (value is PointerOrigin)
         {
             writer.WriteStringValue("pointer");
         }
         else if (value is ElementOrigin element)
         {
             writer.WriteStartObject();
             writer.WriteString("type", "element");
             writer.WritePropertyName("element");
             JsonSerializer.Serialize(writer, element.Element, options);
             writer.WriteEndObject();
         }
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 6
    Low
    • Update

    @nvborisenko nvborisenko merged commit c7e842a into SeleniumHQ:trunk Mar 17, 2025
    9 of 10 checks passed
    @nvborisenko nvborisenko deleted the bidi-input-origin branch March 17, 2025 18:34
    sandeepsuryaprasad pushed a commit to sandeepsuryaprasad/selenium that referenced this pull request Mar 23, 2025
    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