SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.74k stars 8.02k forks source link

[js] Fix locate nodes BiDi test #14140

Closed pujagani closed 1 week ago

pujagani commented 2 weeks ago

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

Motivation and Context

Types of changes

Checklist


PR Type

Bug fix


Description


Changes walkthrough ๐Ÿ“

Relevant files
Bug fix
locate_nodes_test.js
Fix BiDi test by adjusting driver setup and function parameters

javascript/node/selenium-webdriver/test/bidi/locate_nodes_test.js
  • Removed enabling BiDi in Firefox options during driver setup.
  • Modified locateNodes function call to remove an undefined parameter.
  • +2/-2     

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

    codiumai-pr-agent-pro[bot] commented 2 weeks ago

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review [1-5] 2
    ๐Ÿงช Relevant tests No
    ๐Ÿ”’ Security concerns No
    โšก Key issues to review Possible Bug:
    The removal of enableBidi() in Firefox options might affect other tests or functionalities that depend on BiDi features. Ensure that this change does not negatively impact other areas of the testing suite.
    codiumai-pr-agent-pro[bot] commented 2 weeks ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Ensure the driver is properly quit in the afterEach hook to avoid resource leaks ___ **Ensure that the driver is properly quit in the afterEach hook to avoid resource leaks by
    adding await driver.quit() before the hook ends.** [javascript/node/selenium-webdriver/test/bidi/locate_nodes_test.js [39]](https://github.com/SeleniumHQ/selenium/pull/14140/files#diff-d69c46b8235285967e4b9734bfd4b1b4d7a401f4c80086cb2663cef1f43c8298R39-R39) ```diff afterEach(async function () { + if (driver) { + await driver.quit(); + } ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Properly quitting the driver in the `afterEach` hook is crucial to avoid resource leaks and ensure clean test runs. This suggestion directly addresses a common best practice in test teardown.
    8
    Possible issue
    Add error handling for the locateNodes call to manage potential exceptions ___ **Add error handling for the locateNodes call to manage potential exceptions and provide
    more informative test failure messages.** [javascript/node/selenium-webdriver/test/bidi/locate_nodes_test.js [181]](https://github.com/SeleniumHQ/selenium/pull/14140/files#diff-d69c46b8235285967e4b9734bfd4b1b4d7a401f4c80086cb2663cef1f43c8298R181-R181) ```diff -const elements = await browsingContext.locateNodes(Locator.css('div'), 1, sandbox) +let elements; +try { + elements = await browsingContext.locateNodes(Locator.css('div'), 1, sandbox); +} catch (error) { + assert.fail(`locateNodes failed with error: ${error.message}`); +} ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Adding error handling for asynchronous operations like `locateNodes` is important to manage exceptions and provide clearer failure messages, enhancing test robustness and maintainability.
    7
    Add a timeout to the beforeEach and afterEach hooks to prevent tests from hanging indefinitely ___ **Consider adding a timeout to the beforeEach and afterEach hooks to avoid potential issues
    with tests hanging indefinitely if the driver setup or teardown takes too long.** [javascript/node/selenium-webdriver/test/bidi/locate_nodes_test.js [35-39]](https://github.com/SeleniumHQ/selenium/pull/14140/files#diff-d69c46b8235285967e4b9734bfd4b1b4d7a401f4c80086cb2663cef1f43c8298R35-R39) ```diff beforeEach(async function () { + this.timeout(10000); // 10 seconds timeout driver = await env.builder().build() }) afterEach(async function () { + this.timeout(10000); // 10 seconds timeout ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: Adding a timeout can help prevent tests from hanging, which is a good practice, though not critical as the environment might handle timeouts differently.
    6