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

Add BiDi network examples and documentation for Ruby #2100

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

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 f720c45

    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

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Security
    Verify that authentication handlers properly process and validate credentials

    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
    • Apply this suggestion
    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

    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