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

[bidi][js] Add high-level script pinning APIs #14250

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

pujagani
Copy link
Contributor

@pujagani pujagani commented Jul 11, 2024

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.

Description

Related to #13992

Motivation and Context

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

  • Added pin method in Script class to preload scripts.
  • Added unpin method in Script class to remove preloaded scripts.
  • Added tests to verify the functionality of pin and unpin methods.

Changes walkthrough 📝

Relevant files
Enhancement
script.js
Add methods to pin and unpin scripts                                         

javascript/node/selenium-webdriver/lib/script.js

  • Added pin method to preload scripts.
  • Added unpin method to remove preloaded scripts.
  • +10/-0   
    Tests
    webdriver_script_test.js
    Add tests for pinning and unpinning scripts                           

    javascript/node/selenium-webdriver/test/lib/webdriver_script_test.js

    • Added test for pin method.
    • Added test for unpin method.
    +32/-0   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Error Handling
    The methods pin and unpin in the Script class do not handle errors that might occur during script operations. Consider adding try-catch blocks to manage exceptions and provide meaningful error messages to the users.

    Test Timeout
    The test 'can pin script' uses a fixed delay of 3000ms which might lead to flaky tests depending on the environment's performance. Consider using a more dynamic waiting mechanism or increase the timeout to ensure reliability.

    Copy link
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add validation for the script parameter in the pin method to ensure it is non-empty

    Consider checking if the script parameter in the pin method is valid and non-empty
    before attempting to add it as a preload script. This can prevent potential runtime
    errors or the addition of ineffective scripts.

    javascript/node/selenium-webdriver/lib/script.js [116-118]

     async pin(script) {
    +  if (!script) throw new Error('Invalid script provided');
       await this.#initScript()
       return await this.#script.addPreloadScript(script)
     }
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Adding validation for the script parameter is crucial to prevent runtime errors and ensure that only valid scripts are added. This enhances the robustness of the method.

    9
    Enhancement
    Implement error handling in the unpin method to manage exceptions from removePreloadScript

    Add error handling for the removePreloadScript method in the unpin function to
    manage potential failures when removing scripts.

    javascript/node/selenium-webdriver/lib/script.js [121-123]

     async unpin(id) {
       await this.#initScript()
    -  await this.#script.removePreloadScript(id)
    +  try {
    +    await this.#script.removePreloadScript(id)
    +  } catch (error) {
    +    console.error('Failed to unpin script:', error);
    +    throw error;
    +  }
     }
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding error handling in the unpin method is a good practice to manage potential failures gracefully, improving the reliability of the code.

    8
    Improve the assertion method in the unpin script test for better accuracy

    Use a more robust assertion method to check for the absence of log entries after
    unpinning a script, instead of relying on a count that might not accurately reflect
    state changes.

    javascript/node/selenium-webdriver/test/lib/webdriver_script_test.js [155]

    -assert.equal(count, 1)
    +assert.strictEqual(count, 0, 'No log entries should be present after unpinning the script')
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using a more robust assertion method enhances the accuracy of the test, ensuring that the test correctly reflects the state changes after unpinning a script.

    7
    Performance
    Reduce the delay in script pinning tests to enhance test efficiency

    Reduce the hardcoded delay in the test for pinning scripts to improve test execution
    time and efficiency.

    javascript/node/selenium-webdriver/test/lib/webdriver_script_test.js [136]

    -await delay(3000)
    +await delay(1000)  # Reduced delay to improve test speed
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Reducing the delay improves test execution time, but it is important to ensure that the reduced delay does not affect the reliability of the test.

    6

    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