Skip to content

[Java] Update Design Patterns page to use codeblocks #2301

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

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

shbenzer
Copy link
Contributor

@shbenzer shbenzer commented May 5, 2025

User description

Updated java examples in Design Patterns & Development Strategies to use codeblock architecture

Description

Created :

  • BotPattern.java
  • LoadableComponentBasic.java
  • LoadableComponentExtended.java
  • PageObjectTests.java
  • ProjectPage.java
  • SecuredPage.java

Edited:

  • design_strategies.en
  • design_strategies.ja
  • design_strategies.pt-br
  • design_strategies.zh-cn

Motivation and Context

maintains consistency and improves ease of contributions

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

  • 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

  • Refactored Java design pattern examples to use codeblock architecture

    • Added new Java example files for design patterns and strategies
    • Updated all language documentation to embed Java code via codeblocks
  • Improved documentation consistency across English, Japanese, Portuguese, and Chinese

    • Replaced inline Java code with references to example files
    • Ensured code samples are up-to-date and easier to maintain
  • Enhanced maintainability and ease of contributions for documentation and code examples


Changes walkthrough 📝

Relevant files
Enhancement
6 files
BotPattern.java
Add ActionBot class for Java bot pattern example                 
+26/-0   
LoadableComponentBasic.java
Add basic LoadableComponent Java example for EditIssue     
+69/-0   
LoadableComponentExtended.java
Add extended LoadableComponent Java example with PageFactory
+96/-0   
PageObjectTests.java
Add Java test example for nested LoadableComponents           
+30/-0   
ProjectPage.java
Add ProjectPage Java example for LoadableComponent pattern
+28/-0   
SecuredPage.java
Add SecuredPage Java example for authentication in LoadableComponent
+52/-0   
Documentation
4 files
design_strategies.en.md
Update English documentation to embed Java codeblocks       
+182/-334
design_strategies.ja.md
Update Japanese documentation to embed Java codeblocks     
+182/-333
design_strategies.pt-br.md
Update Portuguese documentation to embed Java codeblocks 
+182/-332
design_strategies.zh-cn.md
Update Chinese documentation to embed Java codeblocks       
+182/-332

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 May 5, 2025

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit d2a84d2
    Copy link
    Contributor

    qodo-merge-pro bot commented May 5, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Syntax Error

    There's an extra closing parenthesis in the setTitle method that would cause a compilation error.

    WebElement field = driver.findElement(By.id("issue_title")));
    clearAndType(field, title);
    Variable Reference

    The setSeleniumVersion method incorrectly uses logOutput variable instead of seleniumVersion parameter.

      clearAndType(field, logOutput);
    }
    String Quotes

    The test uses single quotes for string literals instead of double quotes, which is invalid in Java.

    editIssue.title.sendKeys('Title');
    editIssue.body.sendKeys('What Happened');
    editIssue.setHowToReproduce('How to Reproduce');
    editIssue.setLogOutput('Log Output');
    editIssue.setOperatingSystem('Operating System');
    editIssue.setSeleniumVersion('Selenium Version');
    editIssue.setBrowserVersion('Browser Version');
    editIssue.setDriverVersion('Driver Version');
    editIssue.setUsingGrid('I Am Using Grid');
    @shbenzer shbenzer requested a review from harsha509 May 5, 2025 16:23
    Copy link
    Contributor

    qodo-merge-pro bot commented May 5, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix syntax error
    Suggestion Impact:The commit implemented exactly what the suggestion recommended - removing the extra closing parenthesis from the findElement method call to fix the syntax error

    code diff:

    -    WebElement field = driver.findElement(By.id("issue_title")));
    +    WebElement field = driver.findElement(By.id("issue_title"));

    There's an extra closing parenthesis in the findElement method call which will
    cause a syntax error. Remove the extra parenthesis to fix the compilation error.

    examples/java/src/test/java/dev/selenium/design_strategies/LoadableComponentBasic.java [15-18]

     public void setTitle(String title) {
    -  WebElement field = driver.findElement(By.id("issue_title")));
    +  WebElement field = driver.findElement(By.id("issue_title"));
       clearAndType(field, title);
     }

    [Suggestion has been applied]

    Suggestion importance[1-10]: 10

    __

    Why: The suggestion correctly identifies a syntax error (an extra closing parenthesis) in the findElement call within the setTitle method in the new file LoadableComponentBasic.java. This error would prevent the code from compiling.

    High
    Fix incorrect variable usage

    The setSeleniumVersion method incorrectly uses the logOutput variable instead of
    the seleniumVersion parameter. This will cause incorrect data to be entered in
    the Selenium version field.

    examples/java/src/test/java/dev/selenium/design_strategies/LoadableComponentExtended.java [56-59]

     public void setSeleniumVersion(String seleniumVersion) {
       WebElement field = driver.findElement(By.id("issue_form_selenium-version"));
    -  clearAndType(field, logOutput);
    +  clearAndType(field, seleniumVersion);
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: The suggestion correctly identifies a functional bug in the new file LoadableComponentExtended.java. The setSeleniumVersion method incorrectly uses the logOutput variable instead of the seleniumVersion parameter, which would lead to incorrect data being entered.

    High
    Fix string literal syntax

    Replace single quotes with double quotes for string literals. In Java, character
    literals use single quotes while string literals require double quotes.

    examples/java/src/test/java/dev/selenium/design_strategies/PageObjectTests.java [19-27]

    -editIssue.title.sendKeys('Title');
    -editIssue.body.sendKeys('What Happened');
    -editIssue.setHowToReproduce('How to Reproduce');
    -editIssue.setLogOutput('Log Output');
    -editIssue.setOperatingSystem('Operating System');
    -editIssue.setSeleniumVersion('Selenium Version');
    -editIssue.setBrowserVersion('Browser Version');
    -editIssue.setDriverVersion('Driver Version');
    -editIssue.setUsingGrid('I Am Using Grid');
    +editIssue.title.sendKeys("Title");
    +editIssue.body.sendKeys("What Happened");
    +editIssue.setHowToReproduce("How to Reproduce");
    +editIssue.setLogOutput("Log Output");
    +editIssue.setOperatingSystem("Operating System");
    +editIssue.setSeleniumVersion("Selenium Version");
    +editIssue.setBrowserVersion("Browser Version");
    +editIssue.setDriverVersion("Driver Version");
    +editIssue.setUsingGrid("I Am Using Grid");
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: The suggestion correctly identifies a Java syntax error where single quotes are used for multi-character string literals instead of double quotes. Fixing this is essential for the code to compile and run correctly.

    High
    • Update
    @shbenzer shbenzer marked this pull request as draft May 5, 2025 19:02
    @shbenzer shbenzer removed the request for review from harsha509 May 5, 2025 19:02
    @shbenzer shbenzer changed the title [Java] Updated Design Patterns pages to use codeblocks May 5, 2025
    @shbenzer shbenzer changed the title [Java] Update Design Patterns pages to use codeblocks May 5, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    1 participant