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

[js][bidi]: implement bidi getClientWindows command in browser module #15248

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

Conversation

navin772
Copy link
Contributor

@navin772 navin772 commented Feb 6, 2025

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Motivation and Context

Implemented getClientWindows method in JavaScript for BiDi browser module and added a test.

BiDi spec - https://w3c.github.io/webdriver-bidi/#command-browser-getClientWindows

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 getClientWindows command in the BiDi browser module.

  • Added ClientWindowInfo class to represent client window details.

  • Introduced tests for getClientWindows functionality in the BiDi browser.

  • Enhanced BiDi browser module with window state constants.


Changes walkthrough 📝

Relevant files
Enhancement
browser.js
Add `getClientWindows` method to BiDi browser                       

javascript/node/selenium-webdriver/bidi/browser.js

  • Added getClientWindows method to fetch client window details.
  • Imported WindowState and ClientWindowInfo for window handling.
  • Updated module exports to include WindowState.
  • +17/-0   
    clientWindowInfo.js
    Introduce `ClientWindowInfo` class and `WindowState` constants

    javascript/node/selenium-webdriver/bidi/clientWindowInfo.js

  • Created ClientWindowInfo class for client window representation.
  • Defined WindowState constants for window states.
  • Added fromJson method for JSON deserialization.
  • +54/-0   
    Tests
    browser_test.js
    Add tests for `getClientWindows` in BiDi browser                 

    javascript/node/selenium-webdriver/test/bidi/browser_test.js

  • Added test suite for getClientWindows functionality.
  • Validated client window properties and states in tests.
  • Ensured compatibility with multiple browsers.
  • +28/-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

    qodo-merge-pro bot commented Feb 6, 2025

    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

    Input Validation

    The constructor accepts parameters without any type checking or validation. Missing validation for required fields and value ranges could lead to runtime errors.

    constructor({ clientWindow, state, width, height, x, y, active }) {
      this.clientWindow = clientWindow
      this.state = state
      this.width = width
      this.height = height
      this.x = x
      this.y = y
      this.active = active
    }
    Error Handling

    The getClientWindows method does not include error handling for failed responses from the BiDi protocol. Should handle potential error cases.

    async getClientWindows() {
      const command = {
        method: 'browser.getClientWindows',
        params: {},
      }
    
      const response = await this.bidi.send(command)
      return response.result.clientWindows.map((window) => ClientWindowInfo.fromJson(window))
    }

    Copy link
    Contributor

    qodo-merge-pro bot commented Feb 6, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Validate window state during initialization

    Add validation to ensure the window state is a valid value from WindowState enum
    during object construction to prevent invalid states.

    javascript/node/selenium-webdriver/bidi/clientWindowInfo.js [36-44]

     constructor({ clientWindow, state, width, height, x, y, active }) {
    +  if (!Object.values(WindowState).includes(state)) {
    +    throw new Error(`Invalid window state: ${state}`)
    +  }
       this.clientWindow = clientWindow
       this.state = state
       this.width = width
       this.height = height
       this.x = x
       this.y = y
       this.active = active
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion adds crucial validation to prevent invalid window states, which could cause runtime errors. This is particularly important as the WindowState is used throughout the application and invalid states could lead to unexpected behavior.

    Medium
    Validate numeric window parameters

    Add type checking for numeric parameters to ensure valid window dimensions and
    coordinates.

    javascript/node/selenium-webdriver/bidi/clientWindowInfo.js [36-44]

     constructor({ clientWindow, state, width, height, x, y, active }) {
    +  if (!Number.isFinite(width) || !Number.isFinite(height) || !Number.isFinite(x) || !Number.isFinite(y)) {
    +    throw new Error('Window dimensions and coordinates must be valid numbers')
    +  }
       this.clientWindow = clientWindow
       this.state = state
       this.width = width
       this.height = height
       this.x = x
       this.y = y
       this.active = active
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: Adding type validation for numeric parameters is important for preventing invalid window dimensions and coordinates, which could cause rendering issues or crashes. The suggestion uses appropriate Number.isFinite() checks.

    Medium
    Learned
    best practice
    Add parameter validation to ensure all required object properties are provided before using them

    Add parameter validation in the ClientWindowInfo constructor to ensure all
    required window information parameters are provided before using them. This
    prevents potential undefined property access errors.

    javascript/node/selenium-webdriver/bidi/clientWindowInfo.js [36-44]

     constructor({ clientWindow, state, width, height, x, y, active }) {
    +  if (!clientWindow || !state || width == null || height == null || x == null || y == null || active == null) {
    +    throw new Error('Missing required window information parameters')
    +  }
       this.clientWindow = clientWindow
       this.state = state
       this.width = width
       this.height = height
       this.x = x
       this.y = y
       this.active = active
     }
    • Apply this suggestion
    Low

    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