Skip to content

[java]: add docs and example for setNetworkConditions #2071

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 5 commits into from
Nov 22, 2024

Conversation

navin772
Copy link
Member

@navin772 navin772 commented Nov 21, 2024

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

Added docs and examples for setNetworkConditions for Chrome and Edge browsers

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

Tests, Documentation


Description

  • Added Java tests for setting network conditions in Chrome and Edge browsers using ChromiumNetworkConditions.
  • Updated documentation to include new Java example code blocks for network conditions in multiple languages.

Changes walkthrough 📝

Relevant files
Tests
2 files
ChromeTest.java
Add network conditions test for Chrome browser                     

examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java

  • Added a test for setting network conditions in Chrome.
  • Utilized ChromiumNetworkConditions to configure network settings.
  • Verified network conditions using assertions.
  • +26/-1   
    EdgeTest.java
    Add network conditions test for Edge browser                         

    examples/java/src/test/java/dev/selenium/browsers/EdgeTest.java

  • Added a test for setting network conditions in Edge.
  • Used ChromiumNetworkConditions to set network parameters.
  • Included assertions to verify network settings.
  • +26/-1   
    Documentation
    8 files
    chrome.en.md
    Update Java example for Chrome network conditions               

    website_and_docs/content/documentation/webdriver/browsers/chrome.en.md

    • Updated Java example code block for network conditions.
    +1/-1     
    chrome.ja.md
    Update Java example for Chrome network conditions (Japanese)

    website_and_docs/content/documentation/webdriver/browsers/chrome.ja.md

    • Updated Java example code block for network conditions.
    +1/-1     
    chrome.pt-br.md
    Update Java example for Chrome network conditions (Portuguese)

    website_and_docs/content/documentation/webdriver/browsers/chrome.pt-br.md

    • Updated Java example code block for network conditions.
    +1/-1     
    chrome.zh-cn.md
    Update Java example for Chrome network conditions (Chinese)

    website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md

    • Updated Java example code block for network conditions.
    +1/-1     
    edge.en.md
    Update Java example for Edge network conditions                   

    website_and_docs/content/documentation/webdriver/browsers/edge.en.md

    • Updated Java example code block for network conditions.
    +1/-1     
    edge.ja.md
    Update Java example for Edge network conditions (Japanese)

    website_and_docs/content/documentation/webdriver/browsers/edge.ja.md

    • Updated Java example code block for network conditions.
    +1/-1     
    edge.pt-br.md
    Update Java example for Edge network conditions (Portuguese)

    website_and_docs/content/documentation/webdriver/browsers/edge.pt-br.md

    • Updated Java example code block for network conditions.
    +1/-1     
    edge.zh-cn.md
    Update Java example for Edge network conditions (Chinese)

    website_and_docs/content/documentation/webdriver/browsers/edge.zh-cn.md

    • Updated Java example code block for network conditions.
    +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    netlify bot commented Nov 21, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit 4c9e9a9

    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

    Resource Cleanup
    The driver.quit() call should be in a try-finally block to ensure cleanup even if assertions fail

    Resource Cleanup
    The driver.quit() call should be in a try-finally block to ensure cleanup even if assertions fail

    Magic Numbers
    Network condition values like 2000 kbps and 20ms latency should be defined as named constants with clear units

    Copy link
    Contributor

    qodo-merge-pro bot commented Nov 21, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    ✅ Reset network conditions after test execution to prevent interference with subsequent tests
    Suggestion Impact:The commit added a cleanup step for network conditions using deleteNetworkConditions() in the test teardown, which aligns with the suggestion to reset network conditions.

    code diff:

    +    ((ChromeDriver) driver).deleteNetworkConditions();

    Add cleanup of network conditions in the test teardown to ensure subsequent tests
    aren't affected by modified network settings.

    examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java [200-223]

     @Test
     public void setNetworkConditions() {
       driver = new ChromeDriver();
    -  // ... network conditions setup ...
    -  driver.quit();
    +  try {
    +    // ... network conditions setup ...
    +  } finally {
    +    ((ChromeDriver) driver).setNetworkConditions(new ChromiumNetworkConditions());
    +    driver.quit();
    +  }
     }
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a potential test isolation issue by ensuring network conditions are reset after the test, which could affect other tests. This is a critical testing best practice that improves test reliability and maintainability.

    8

    💡 Need additional feedback ? start a PR chat

    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.

    Thank you @navin772 !

    @harsha509 harsha509 merged commit 5b50534 into SeleniumHQ:trunk Nov 22, 2024
    9 checks passed
    @navin772 navin772 deleted the java-setNetworkConditions branch November 22, 2024 18:05
    selenium-ci added a commit that referenced this pull request Nov 22, 2024
    …site]
    
    * add example for java setNetworkConditions in chrome and edge
    
    * java docs for setNetworkConditions
    
    * delete network conditions after assertions
    
    ---------
    
    Co-authored-by: Sri Harsha <[email protected]> 5b50534
    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