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] Second round of BiDi implementation #14566

Draft
wants to merge 65 commits into
base: trunk
Choose a base branch
from

Conversation

nvborisenko
Copy link
Member

@nvborisenko nvborisenko commented Oct 4, 2024

User description

Description

This is implementation of new core concepts in BiDi world mapped to .Net. Including new unit tests.

Motivation and Context

Addresses #14530

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, Tests


Description

  • Implemented new core concepts in the BiDi module for .Net, including refactoring and enhancements across multiple components.
  • Added extensive unit tests covering various functionalities such as BrowsingContext, Script, Network, Input, and Storage modules.
  • Refactored type definitions and method signatures to improve code clarity and performance.
  • Introduced new JSON converters for handling serialization and deserialization of complex types.
  • Enhanced input handling with new SourceActions and related converters.
  • Updated network module to support authentication event subscriptions and improved request handling.
  • Simplified and improved logging functionalities with new Entry records and log level enums.

Changes walkthrough 📝

Relevant files
Enhancement
55 files
RemoteValue.cs
Refactor and Update RemoteValue Type Handling                       

dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs

  • Updated type names for JsonDerivedType attributes.
  • Modified implicit operator conversions for RemoteValue.
  • Added handling for boolean type conversion.
  • Refactored record definitions for various remote values.
  • +159/-145
    BrowsingContext.cs
    Refactor BrowsingContext Method Calls and Return Types     

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

  • Updated method calls to use BiDi.BrowsingContext instead of
    BiDi.BrowsingContextModule.
  • Changed return type for LocateNodesAsync.
  • +27/-27 
    ScriptModule.cs
    Update ScriptModule Methods and Add Event Subscriptions   

    dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs

  • Updated return types for EvaluateAsync and CallFunctionAsync.
  • Added subscription methods for script events.
  • +53/-10 
    SourceActions.cs
    Add SourceActions for Input Handling                                         

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

  • Introduced SourceActions and its derived records for input actions.
  • Defined records for key, pointer, and wheel actions.
  • +150/-0 
    LocalValue.cs
    Refactor LocalValue Type Definitions                                         

    dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs

  • Refactored LocalValue and its derived records.
  • Updated type names for JsonDerivedType attributes.
  • +52/-35 
    BiDi.cs
    Rename ScriptModule and BrowsingContextModule Properties 

    dotnet/src/webdriver/BiDi/BiDi.cs

  • Renamed ScriptModule to Script and BrowsingContextModule to
    BrowsingContext.
  • +2/-53   
    RemoteValueConverter.cs
    Update RemoteValueConverter for New Types                               

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs

  • Updated deserialization logic for RemoteValue types.
  • Added handling for boolean and array types.
  • +30/-23 
    RealmInfo.cs
    Refactor RealmInfo Type Definitions                                           

    dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs

  • Refactored RealmInfo and its derived records.
  • Updated type names for JsonDerivedType attributes.
  • +21/-22 
    NetworkModule.cs
    Rename and Enhance NetworkModule Authentication Methods   

    dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs

  • Renamed InterceptAuthenticationAsync to InterceptAuthAsync.
  • Added public methods for authentication event subscriptions.
  • +10/-5   
    BrowsingContextScriptModule.cs
    Update BrowsingContextScriptModule for Target Context       

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

  • Updated method calls to use Target.Context.
  • Added generic return type methods for script evaluations.
  • +14/-7   
    Locator.cs
    Refactor Locator Type Definitions                                               

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

  • Refactored Locator and its derived records.
  • Updated type names for JsonDerivedType attributes.
  • +24/-34 
    PerformActionsCommand.cs
    Simplify PerformActionsCommandParameters Definition           

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

  • Simplified PerformActionsCommandParameters definition.
  • Removed redundant records for key actions.
  • +2/-66   
    GetCookiesCommand.cs
    Refactor GetCookiesResult and PartitionDescriptor               

    dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs

  • Refactored GetCookiesResult to implement IReadOnlyList.
  • Updated PartitionDescriptor and its derived records.
  • +36/-11 
    ProxyConfiguration.cs
    Refactor ProxyConfiguration Type Definitions                         

    dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs

  • Refactored ProxyConfiguration and its derived records.
  • Updated type names for JsonDerivedType attributes.
  • +20/-19 
    UrlPattern.cs
    Refactor UrlPattern Type Definitions                                         

    dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs

  • Refactored UrlPattern and its derived records.
  • Updated type names for JsonDerivedType attributes.
  • +15/-17 
    BrowsingContextNetworkModule.cs
    Rename and Enhance BrowsingContextNetworkModule Auth Methods

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

  • Renamed InterceptAuthenticationAsync to InterceptAuthAsync.
  • Added public methods for authentication event subscriptions.
  • +7/-2     
    RealmInfoConverter.cs
    Update RealmInfoConverter for New Type Names                         

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs

  • Updated deserialization logic for RealmInfo types.
  • Refactored to use new type names for RealmInfo.
  • +8/-8     
    InputSourceActionsConverter.cs
    Implement InputSourceActionsConverter for SourceActions   

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs

  • Implemented InputSourceActionsConverter for serializing SourceActions.
  • Added logic for handling different action types.
  • +51/-0   
    Broker.cs
    Add JSON Converters for BiDi Modules                                         

    dotnet/src/webdriver/BiDi/Communication/Broker.cs

  • Added new JSON converters for various BiDi modules.
  • Included converters for enumerable and polymorphic types.
  • +9/-1     
    ContinueWithAuthCommand.cs
    Refactor ContinueWithAuthParameters Type Definitions         

    dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs

  • Refactored ContinueWithAuthParameters and its derived records.
  • Updated type names for JsonDerivedType attributes.
  • +15/-10 
    AddPreloadScriptCommand.cs
    Update AddPreloadScriptCommand for LocalValue.Channel       

    dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs

  • Updated AddPreloadScriptCommandParameters to use LocalValue.Channel.
  • Refactored related options and parameters.
  • +3/-3     
    LogEntryConverter.cs
    Update LogEntryConverter for New Type Names                           

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs

  • Updated deserialization logic for LogEntry types.
  • Refactored to use new type names for LogEntry.
  • +5/-5     
    MessageEventArgs.cs
    Add MessageEventArgs for Script Message Events                     

    dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs

    • Added MessageEventArgs record for script message events.
    +3/-0     
    BrowsingContextModule.cs
    Update LocateNodesAsync to return LocateNodesResult directly.

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

  • Changed return type of LocateNodesAsync method to LocateNodesResult.
  • Simplified the method by removing intermediate variable.
  • +2/-4     
    BrowsingContextLogModule.cs
    Update log entry handler types in BrowsingContextLogModule.

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

  • Updated OnEntryAddedAsync method signatures to use Log.Entry instead
    of BaseLogEntry.
  • +2/-2     
    InputModule.cs
    Modify PerformActionsAsync to accept actions parameter directly.

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

  • Added actions parameter to PerformActionsAsync method.
  • Removed conditional assignment of actions from options.
  • +4/-8     
    BrowsingContextStorageModule.cs
    Refactor partition assignment in BrowsingContextStorageModule.

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

    • Updated partition assignment to use PartitionDescriptor.Context.
    +3/-3     
    EvaluateCommand.cs
    Refactor EvaluateResult to use nested records.                     

    dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs

  • Refactored EvaluateResult to include nested Success and Exception
    records.
  • +10/-6   
    LocateNodesCommand.cs
    Implement LocateNodesResult as IReadOnlyList.                       

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

  • Implemented LocateNodesResult as a class implementing IReadOnlyList.
  • +18/-1   
    Entry.cs
    Add Entry record and Level enum for logging.                         

    dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs

  • Introduced Entry record with nested Console and Javascript records.
  • Defined Level enum for log levels.
  • +28/-0   
    InputOriginConverter.cs
    Add JSON converter for Input Origin types.                             

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

    • Implemented InputOriginConverter for serializing Origin types.
    +34/-0   
    CaptureScreenshotCommand.cs
    Refactor ClipRectangle to use nested records.                       

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

  • Refactored ClipRectangle to use nested Box and Element records.
  • +11/-6   
    GetUserContextsCommand.cs
    Implement GetUserContextsResult as IReadOnlyList.               

    dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs

  • Implemented GetUserContextsResult as a class implementing
    IReadOnlyList.
  • +18/-1   
    GetRealmsCommand.cs
    Implement GetRealmsResult as IReadOnlyList.                           

    dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs

  • Implemented GetRealmsResult as a class implementing IReadOnlyList.
  • +18/-1   
    RealmTypeConverter.cs
    Implement Write method in RealmTypeConverter.                       

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

    • Implemented Write method for RealmTypeConverter.
    +14/-1   
    GetCookiesResultConverter.cs
    Add JSON converter for GetCookiesResult.                                 

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs

  • Implemented GetCookiesResultConverter for deserializing
    GetCookiesResult.
  • +24/-0   
    Target.cs
    Refactor Target to use nested records.                                     

    dotnet/src/webdriver/BiDi/Modules/Script/Target.cs

    • Refactored Target to use nested Realm and Context records.
    +15/-7   
    GetUserContextsResultConverter.cs
    Add JSON converter for GetUserContextsResult.                       

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs

  • Implemented GetUserContextsResultConverter for deserializing
    GetUserContextsResult.
  • +23/-0   
    LocateNodesResultConverter.cs
    Add JSON converter for LocateNodesResult.                               

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs

  • Implemented LocateNodesResultConverter for deserializing
    LocateNodesResult.
  • +24/-0   
    GetRealmsResultConverter.cs
    Add JSON converter for GetRealmsResult.                                   

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs

  • Implemented GetRealmsResultConverter for deserializing
    GetRealmsResult.
  • +23/-0   
    BrowserModule.cs
    Update GetUserContextsAsync to return GetUserContextsResult directly.

    dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs

  • Changed return type of GetUserContextsAsync to GetUserContextsResult.
  • Simplified the method by removing intermediate variable.
  • +2/-4     
    NodeProperties.cs
    Update NodeProperties to use RemoteValue.Node types.         

    dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs

  • Updated types for Children and ShadowRoot properties to
    RemoteValue.Node.
  • +2/-2     
    LogModule.cs
    Update log entry handler types in LogModule.                         

    dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs

  • Updated OnEntryAddedAsync method signatures to use Entry instead of
    BaseLogEntry.
  • +2/-2     
    BytesValue.cs
    Refactor BytesValue to use nested records.                             

    dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs

  • Refactored BytesValue to use nested String and Base64 records.
  • +6/-6     
    UserContext.cs
    Update UserContext with internal Id and equality methods.

    dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs

  • Changed Id property to internal.
  • Added Equals and GetHashCode methods.
  • +13/-1   
    EvaluateResultConverter.cs
    Update EvaluateResultConverter for nested result types.   

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs

  • Updated deserialization to use nested EvaluateResult.Success and
    EvaluateResult.Exception.
  • +2/-2     
    ChannelConverter.cs
    Simplify ChannelConverter by removing BiDi dependency.     

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

    • Removed BiDi dependency from ChannelConverter.
    +1/-8     
    BrowsingContextInputModule.cs
    Simplify PerformActionsAsync in BrowsingContextInputModule.

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

  • Simplified PerformActionsAsync by removing redundant options
    assignment.
  • +5/-4     
    AuthCredentials.cs
    Refactor AuthCredentials to use nested Basic record.         

    dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs

    • Refactored AuthCredentials to use nested Basic record.
    +3/-3     
    Origin.cs
    Add Origin record with nested types for input.                     

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

  • Introduced Origin record with nested Viewport, Pointer, and Element
    records.
  • +18/-0   
    ScriptEvaluateException.cs
    Update ScriptEvaluateException to use nested exception type.

    dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs

  • Updated ScriptEvaluateException to use EvaluateResult.Exception.
  • +2/-2     
    PreloadScript.cs
    Update PreloadScript to call RemovePreloadScriptAsync.     

    dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs

    • Updated method call to RemovePreloadScriptAsync.
    +1/-1     
    Channel.cs
    Refactor Channel to a simple record with Id.                         

    dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs

    • Refactored Channel to a record with a single Id property.
    +1/-12   
    PartitionKey.cs
    Update PartitionKey to use Browser.UserContext type.         

    dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs

    • Updated UserContext property type to Browser.UserContext.
    +1/-1     
    RealmDestroyedEventArgs.cs
    Add RealmDestroyedEventArgs record for script module.       

    dotnet/src/webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs

    • Added new RealmDestroyedEventArgs record.
    +3/-0     
    Tests
    13 files
    BrowsingContextTest.cs
    Add Unit Tests for BrowsingContext Functionalities             

    dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs

  • Added new unit tests for BrowsingContext functionalities.
  • Tests cover context creation, navigation, and manipulation.
  • +300/-0 
    CallFunctionParameterTest.cs
    Add Tests for Script Function Call Parameters                       

    dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs

  • Added tests for script function calls with various parameters.
  • Included tests for function calls with await and ownership options.
  • +203/-0 
    NetworkTest.cs
    Add Network Request Interception and Auth Tests                   

    dotnet/test/common/BiDi/Network/NetworkTest.cs

  • Introduced tests for network request interception and continuation.
  • Added tests for authentication handling in network requests.
  • +193/-0 
    NetworkEventsTest.cs
    Add Tests for Network Event Listeners                                       

    dotnet/test/common/BiDi/Network/NetworkEventsTest.cs

  • Implemented tests for network event listeners.
  • Included tests for request and response events.
  • +132/-0 
    ScriptCommandsTest.cs
    Add Tests for Script Command Functionalities                         

    dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs

  • Added tests for script command functionalities.
  • Included tests for realm management and preload scripts.
  • +150/-0 
    StorageTest.cs
    Add Tests for Storage Cookie Management                                   

    dotnet/test/common/BiDi/Storage/StorageTest.cs

  • Added tests for cookie management in storage module.
  • Included tests for adding, retrieving, and deleting cookies.
  • +161/-0 
    EvaluateParametersTest.cs
    Add Tests for Script Evaluation Parameters                             

    dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs

  • Added tests for evaluating scripts with various parameters.
  • Included tests for sandbox and realm evaluations.
  • +109/-0 
    LogTest.cs
    Add Tests for Logging Functionalities                                       

    dotnet/test/common/BiDi/Log/LogTest.cs

  • Added tests for logging functionalities.
  • Included tests for console and JavaScript log entries.
  • +75/-0   
    ScriptEventsTest.cs
    Add Tests for Script Event Listeners                                         

    dotnet/test/common/BiDi/Script/ScriptEventsTest.cs

  • Added tests for script event listeners.
  • Included tests for channel messages and realm events.
  • +63/-0   
    CombinedInputActionsTest.cs
    Add Tests for Combined Input Actions                                         

    dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs

  • Added tests for combined input actions.
  • Included tests for pointer and key actions.
  • +54/-0   
    BrowserTest.cs
    Add Tests for Browser User Context Management                       

    dotnet/test/common/BiDi/Browser/BrowserTest.cs

  • Added tests for browser user context management.
  • Included tests for creating, retrieving, and removing user contexts.
  • +43/-0   
    BiDiFixture.cs
    Introduce BiDiFixture for Test Setup and Teardown               

    dotnet/test/common/BiDi/BiDiFixture.cs

  • Introduced BiDiFixture for setting up BiDi tests.
  • Configured setup and teardown methods for BiDi context.
  • +53/-0   
    DefaultMouseTest.cs
    Add test for mouse drag and drop actions.                               

    dotnet/test/common/BiDi/Input/DefaultMouseTest.cs

    • Added a new test PerformDragAndDropWithMouse for mouse actions.
    +37/-0   
    Configuration changes
    1 files
    DriverFactory.cs
    Enable additional Chrome options in DriverFactory.             

    dotnet/test/common/Environment/DriverFactory.cs

  • Enabled UnhandledPromptBehavior and UseWebSocketUrl options for
    Chrome.
  • +3/-2     
    Formatting
    1 files
    Subscription.cs
    Rename Broker to _broker in Subscription class.                   

    dotnet/src/webdriver/BiDi/Subscription.cs

    • Renamed Broker to _broker for consistency.
    +3/-3     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @nvborisenko nvborisenko marked this pull request as draft October 9, 2024 21:52
    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