Skip to content

Conversation

aguspe
Copy link
Contributor

@aguspe aguspe commented Dec 14, 2024

User description

Description

This PR adds documentation for the work done in #13993

And it also adds examples for the upcoming Response handler method

Motivation and Context

To facilitate use and adoption of the new BiDi implementation is important that the documentation is up to date with relevant examples

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

PR Type

Documentation, Enhancement


Description

  • Added comprehensive Ruby examples for BiDi network functionality including authentication, request, and response handlers
  • Added detailed documentation explaining each handler type and their use cases
  • Updated documentation in multiple languages (Japanese, Portuguese, Chinese) with the new BiDi network content
  • Implemented RSpec tests to validate network handler functionality
  • Fixed documentation alias paths to use English version as reference

Changes walkthrough 📝

Relevant files
Tests
network_spec.rb
Add BiDi network handler tests for Ruby                                   

examples/ruby/spec/bidi/network_spec.rb

  • Added new RSpec tests for BiDi network functionality
  • Implemented tests for authentication, request, and response handlers
  • Added tests for handler management (remove and clear handlers)
  • +39/-0   
    Documentation
    network.en.md
    Add BiDi network handlers documentation with Ruby examples

    website_and_docs/content/documentation/webdriver/bidi/network.en.md

  • Added detailed documentation for authentication, request, and response
    handlers
  • Added Ruby code examples for each handler type
  • Added sections for handler management (remove and clear)
  • +99/-0   
    network.ja.md
    Update Japanese translation with BiDi network documentation

    website_and_docs/content/documentation/webdriver/bidi/network.ja.md

  • Updated documentation with English BiDi network content
  • Fixed alias path to use English version
  • Added Ruby code examples for network handlers
  • +100/-1 
    network.pt-br.md
    Update Portuguese translation with BiDi network documentation

    website_and_docs/content/documentation/webdriver/bidi/network.pt-br.md

  • Updated documentation with English BiDi network content
  • Fixed alias path to use English version
  • Added Ruby code examples for network handlers
  • +100/-1 
    network.zh-cn.md
    Update Chinese translation with BiDi network documentation

    website_and_docs/content/documentation/webdriver/bidi/network.zh-cn.md

  • Updated documentation with English BiDi network content
  • Fixed alias path to use English version
  • Added Ruby code examples for network handlers
  • +100/-1 

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

    Copy link

    netlify bot commented Dec 14, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit ac5d9c6

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Test Coverage
    The network handler tests only verify the handler count but do not validate the actual functionality or behavior of the handlers

    Error Handling
    The tests do not include error cases or validation of error scenarios when adding/removing handlers

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 14, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Security
    Verify that authentication handlers properly process and validate credentials
    Suggestion Impact:The commit changed the authentication handler test to actually verify authentication functionality by navigating to a page requiring authentication and checking if it worked, rather than just checking if the handler was added.

    code diff:

    -  it 'adds an auth handler' do
    -    network = driver.network
    -    network.add_authentication_handler('username', 'password')
    -    expect(network.callbacks.count).to be 1
    -  end
    -
    -  it 'adds a request handler' do
    -    network = driver.network
    -    network.add_request_handler
    -    expect(network.callbacks.count).to be 1
    -  end
    -
    -  it 'adds a response handler' do
    -    network = driver.network
    -    network.add_response_handler
    -    expect(network.callbacks.count).to be 1
    -  end
    -
    -  it 'removes a handler' do
    -    network = driver.network
    -    id = network.add_request_handler
    -    network.remove_handler(id)
    -    expect(network.callbacks.count).to be 0
    -  end
    -
    -  it 'clears all handlers' do
    -    network = driver.network
    -    network.add_request_handler
    -    network.add_request_handler
    -    network.clear_handlers
    -    expect(network.callbacks.count).to be 0
    +  it 'adds an auth handler', skip: 'Do not execute BiDi test' do
    +    driver.network.add_authentication_handler('test', 'test')
    +    driver.navigate.to url_for('basicAuth')
    +    expect(driver.find_element(tag_name: 'h1').text).to eq('authorized')
       end

    Add test cases to verify that authentication handlers correctly handle the provided
    credentials.

    examples/ruby/spec/bidi/network_spec.rb [9-10]

    -network.add_authentication_handler('username', 'password')
    -expect(network.callbacks.count).to be 1
    +auth_called = false
    +network.add_authentication_handler('username', 'password') do |auth|
    +  auth_called = true
    +  expect(auth.credentials.username).to eq('username')
    +  expect(auth.credentials.password).to eq('password')
    +end
    +# Trigger auth request
    +expect(auth_called).to be true

    [Suggestion has been applied]

    Suggestion importance[1-10]: 9

    Why: This security-focused enhancement ensures proper credential handling and validation, which is critical for authentication functionality. The suggestion adds essential verification of the authentication mechanism.

    9
    General
    Include handler implementation examples to demonstrate actual request/response interception functionality

    Add a block parameter to the request and response handler methods to demonstrate how
    to actually handle the intercepted requests/responses. The current tests only verify
    handler registration but not their functionality.

    examples/ruby/spec/bidi/network_spec.rb [15-16]

    -network.add_request_handler
    +network.add_request_handler do |request|
    +  # Example: Modify request headers
    +  request.headers['Custom-Header'] = 'test'
    +end
     expect(network.callbacks.count).to be 1
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion significantly improves test quality by demonstrating actual handler functionality instead of just verifying registration. This makes the tests more meaningful and provides valuable implementation examples.

    8
    Add test coverage for error scenarios in handler removal functionality

    Add error handling test cases to verify the behavior when invalid handler IDs are
    provided to remove_handler.

    examples/ruby/spec/bidi/network_spec.rb [28-29]

    +expect { network.remove_handler('invalid_id') }.to raise_error(StandardError)
     network.remove_handler(id)
     expect(network.callbacks.count).to be 0
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding error handling test cases is important for robustness, ensuring the system handles invalid handler IDs gracefully. This improves code reliability and documentation.

    7

    Copy link

    @A1exKH A1exKH left a comment

    Choose a reason for hiding this comment

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

    @aguspe LGTM.

    @diemol
    Copy link
    Member

    diemol commented Aug 17, 2025

    @aguspe, what is missing in this PR?

    @aguspe
    Copy link
    Contributor Author

    aguspe commented Aug 18, 2025

    @diemol now it will be ready to merge, but I noticed some issues with other examples outside of this PR, so I'm waiting to see if my changes fixed them so the Ruby pipeline is green again

    harsha509
    harsha509 previously approved these changes Aug 18, 2025
    Copy link
    Member

    @harsha509 harsha509 left a comment

    Choose a reason for hiding this comment

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

    LGTM,
    re-ran failed test, waiting for CI to pass ✅

    @harsha509
    Copy link
    Member

    @aguspe can you also create issues and tag them as needs translation based on the changes made in this PR?

    @aguspe
    Copy link
    Contributor Author

    aguspe commented Aug 18, 2025

    Absolutely @harsha509 i will do that tomorrow😊

    @diemol
    Copy link
    Member

    diemol commented Aug 18, 2025

    Can you please skip the IE tests? I believe we don't have the binary present in GH runners anymore.

    @aguspe
    Copy link
    Contributor Author

    aguspe commented Aug 18, 2025

    Can you please skip the IE tests? I believe we don't have the binary present in GH runners anymore.

    no problem, I just pushed the changes now, I will need a re-review @harsha509 thank you!

    @diemol diemol merged commit 201a257 into SeleniumHQ:trunk Aug 18, 2025
    10 checks passed
    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.

    5 participants