Skip to content

[java] show relevant code for elements/information #2194

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

Merged
merged 3 commits into from
Mar 10, 2025

Conversation

Delta456
Copy link
Member

@Delta456 Delta456 commented Feb 25, 2025

User description

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

Removed assert from code snippet for Java binding and format comments

Motivation and Context

Will be accurate and less noise

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

  • [ x I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

PR Type

Enhancement, Documentation


Description

  • Improved Java code examples by standardizing comment formatting.

  • Updated documentation references to reflect adjusted Java code line ranges.

  • Enhanced readability and clarity of Java test code snippets.

  • Synchronized documentation across multiple languages with updated Java code references.


Changes walkthrough 📝

Relevant files
Enhancement
InformationTest.java
Standardized and clarified Java test code comments             

examples/java/src/test/java/dev/selenium/elements/InformationTest.java

  • Standardized comment formatting for better readability.
  • Adjusted indentation and spacing in Java test code.
  • Improved clarity of comments explaining element methods.
  • +12/-12 
    Documentation
    information.en.md
    Updated English documentation with new Java line references

    website_and_docs/content/documentation/webdriver/elements/information.en.md

  • Updated Java code line references in documentation.
  • Adjusted line ranges to match updated Java code.
  • +8/-8     
    information.ja.md
    Updated Japanese documentation with new Java line references

    website_and_docs/content/documentation/webdriver/elements/information.ja.md

  • Updated Java code line references in Japanese documentation.
  • Adjusted line ranges to match updated Java code.
  • +8/-8     
    information.pt-br.md
    Updated Portuguese documentation with new Java line references

    website_and_docs/content/documentation/webdriver/elements/information.pt-br.md

  • Updated Java code line references in Portuguese documentation.
  • Adjusted line ranges to match updated Java code.
  • +7/-7     
    information.zh-cn.md
    Updated Chinese documentation with new Java line references

    website_and_docs/content/documentation/webdriver/elements/information.zh-cn.md

  • Updated Java code line references in Chinese documentation.
  • Adjusted line ranges to match updated Java code.
  • +8/-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

    netlify bot commented Feb 25, 2025

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit dc2eb82

    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

    Code Style

    Inconsistent spacing around equals signs in assertions. Some assertions have spaces around equals (e.g. isEmailVisible, true) while others don't. Should standardize for better readability.

       boolean isEmailVisible = driver.findElement(By.name("email_input")).isDisplayed();
       assertEquals(isEmailVisible,true);
    
       // isEnabled
       // returns true if element is enabled else returns false
       boolean isEnabledButton = driver.findElement(By.name("button_input")).isEnabled();
       assertEquals(isEnabledButton,true);
    
       // isSelected
       // returns true if element is checked else returns false
       boolean isSelectedCheck = driver.findElement(By.name("checkbox_input")).isSelected();
       assertEquals(isSelectedCheck,true); 
    
       // TagName
       // returns TagName of the element
       String tagNameInp = driver.findElement(By.name("email_input")).getTagName();
       assertEquals(tagNameInp,"input"); 
    
       // GetRect
       // Returns height, width, x and y coordinates referenced element
       Rectangle res =  driver.findElement(By.name("range_input")).getRect();
       // Rectangle class provides getX,getY, getWidth, getHeight methods
       assertEquals(res.getX(),10);
    
    
    // Retrieves the computed style property 'font-size' of field
    String cssValue = driver.findElement(By.name("color_input")).getCssValue("font-size");
    assertEquals(cssValue, "13.3333px");
    
    
      // GetText
      // Retrieves the text of the element
       String text = driver.findElement(By.tagName("h1")).getText();
       assertEquals(text, "Testing Inputs");
    
    
     // FetchAttributes
     // identify the email text box
     WebElement emailTxt = driver.findElement(By.name(("email_input")));
     // fetch the value property associated with the textbox
     String valueInfo = emailTxt.getAttribute("value");
     assertEquals(valueInfo,"admin@localhost");

    Copy link
    Contributor

    qodo-merge-pro bot commented Feb 25, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add WebDriver cleanup

    Add cleanup by closing the WebDriver instance after test execution to prevent
    resource leaks

    examples/java/src/test/java/dev/selenium/elements/InformationTest.java [17-19]

     public void informationWithElements() {
         WebDriver driver = new ChromeDriver();
    -    driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
    +    try {
    +        driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
    +    } finally {
    +        driver.quit();
    +    }

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 8

    __

    Why: Not closing WebDriver instances can lead to memory leaks and orphaned browser processes. Adding proper cleanup with try-finally ensures resources are released even if test fails.

    Medium
    • Update

    Copy link
    Member

    @harsha509 harsha509 left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    LGTM!
    Thank you @Delta456 !

    @harsha509
    Copy link
    Member

    I believe the failures are not related to this PR!

    @harsha509 harsha509 merged commit 559f4be into SeleniumHQ:trunk Mar 10, 2025
    7 of 9 checks passed
    selenium-ci added a commit that referenced this pull request Mar 10, 2025
    @Delta456 Delta456 deleted the info_java branch March 11, 2025 09:53
    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.

    2 participants