SeleniumHQ / seleniumhq.github.io

Official Selenium website and documentation
https://selenium.dev
Apache License 2.0
1.09k stars 1.28k forks source link

Fix typos in two files #1889

Open Tuscann opened 3 weeks ago

Tuscann commented 3 weeks ago

User description

In two files fixed typos and refactor the files.

Fixes #1

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

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

Description

Motivation and Context

Types of changes

Checklist


PR Type

enhancement


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
InformationTest.java
Refactor and improve readability of InformationTest.java 

examples/java/src/test/java/dev/selenium/elements/InformationTest.java
  • Refactored code for better readability and consistency.
  • Fixed indentation and spacing issues.
  • Improved comments for clarity.
  • +46/-51 
    InteractionTest.java
    Refactor and improve readability of InteractionTest.java 

    examples/java/src/test/java/dev/selenium/elements/InteractionTest.java
  • Refactored code for better readability and consistency.
  • Fixed spacing and formatting issues.
  • Enhanced comments for clarity.
  • +17/-19 

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

    netlify[bot] commented 3 weeks ago

    Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    Latest commit 85cdbf64cef3d284f3f240c1f650dbf80dc0ead9
    CLAassistant commented 3 weeks ago

    CLA assistant check
    All committers have signed the CLA.

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

    PR Reviewer Guide πŸ”

    ⏱️ Estimated effort to review: 2 πŸ”΅πŸ”΅βšͺβšͺβšͺ
    πŸ§ͺ No relevant tests
    πŸ”’ No security concerns identified
    ⚑ Key issues to review

    Code Smell
    The `informationWithElements` method is quite long and could be split into smaller, more focused methods for better readability and maintainability. Possible Bug
    The `checkInput` variable is used before it's declared, which might cause a compilation error.
    codiumai-pr-agent-pro[bot] commented 3 weeks ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use try-with-resources to automatically close the WebDriver ___ **Consider using a try-with-resources statement to ensure that the WebDriver is closed
    properly, even if an exception occurs during the test execution.** [examples/java/src/test/java/dev/selenium/elements/InformationTest.java [17-64]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1889/files#diff-0b4391cb08e5ebe306737f17d3ab82491305d36681b47d08bc431f4c0c66c527R17-R64) ```diff -WebDriver driver = new ChromeDriver(); -driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500)); -// Navigate to Url -driver.get("https://www.selenium.dev/selenium/web/inputs.html"); -... -driver.quit(); +try (WebDriver driver = new ChromeDriver()) { + driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500)); + // Navigate to Url + driver.get("https://www.selenium.dev/selenium/web/inputs.html"); + ... + // No need for explicit driver.quit() here +} ```
    Suggestion importance[1-10]: 9 Why: This suggestion is a best practice that ensures the WebDriver is closed properly, even if an exception occurs, improving resource management and reliability of the test.
    9
    Maintainability
    Use a constant for the test URL instead of hardcoding it ___ **Consider using a constant or a configuration file for the URL instead of hardcoding
    it in the test method.** [examples/java/src/test/java/dev/selenium/elements/InteractionTest.java [11]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1889/files#diff-183835d54465a6295362d7d9e20c994a7510839ec8601da62e3763b2cb70b1bbR11-R11) ```diff -driver.get("https://www.selenium.dev/selenium/web/inputs.html"); +private static final String TEST_URL = "https://www.selenium.dev/selenium/web/inputs.html"; +... +driver.get(TEST_URL); ```
    Suggestion importance[1-10]: 8 Why: This suggestion improves maintainability by avoiding hardcoded values, making it easier to update the URL in the future if needed.
    8
    Enhancement
    Use assertTrue for boolean assertions instead of assertEquals with true ___ **Replace the boolean literal true with the actual boolean value in the assertions to
    improve readability and make the test more self-explanatory.** [examples/java/src/test/java/dev/selenium/elements/InformationTest.java [24-25]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1889/files#diff-0b4391cb08e5ebe306737f17d3ab82491305d36681b47d08bc431f4c0c66c527R24-R25) ```diff boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed(); -assertEquals(isEmailVisible, true); +assertTrue(isEmailVisible); ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Using assertTrue improves readability and makes the test more self-explanatory, which is a good enhancement for code clarity.
    7
    Use assertFalse for boolean assertions instead of assertEquals with false ___ **Consider using JUnit's assertFalse method instead of assertEquals when checking if a
    boolean value is false. This improves readability and provides a more specific
    assertion.** [examples/java/src/test/java/dev/selenium/elements/InteractionTest.java [16-17]](https://github.com/SeleniumHQ/seleniumhq.github.io/pull/1889/files#diff-183835d54465a6295362d7d9e20c994a7510839ec8601da62e3763b2cb70b1bbR16-R17) ```diff -Boolean isChecked = checkInput.isSelected(); -assertEquals(isChecked, false); +boolean isChecked = checkInput.isSelected(); +assertFalse(isChecked); ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Using assertFalse enhances readability and provides a more specific assertion, which is a beneficial enhancement for code clarity.
    7