Skip to content
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

[java]: add docs for casting in java for chrome and edge #2077

Merged
merged 5 commits into from
Nov 27, 2024

Conversation

navin772
Copy link
Contributor

@navin772 navin772 commented Nov 25, 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 for casting in java for chrome and edge

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

documentation, tests


Description

  • Added new test methods castFeatures for both Chrome and Edge browsers to manage cast sinks and tab mirroring.
  • Updated documentation to include references to the new Java code examples for casting features in Chrome and Edge.
  • Enhanced the documentation in multiple languages to reflect the new Java code examples.

Changes walkthrough 📝

Relevant files
Tests
2 files
ChromeTest.java
Add casting feature tests for Chrome browser                         

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

  • Added a new test method castFeatures for Chrome.
  • Utilizes ChromeDriver to manage cast sinks and tab mirroring.
  • +15/-1   
    EdgeTest.java
    Add casting feature tests for Edge browser                             

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

  • Added a new test method castFeatures for Edge.
  • Utilizes EdgeDriver to manage cast sinks and tab mirroring.
  • +15/-1   
    Documentation
    8 files
    chrome.en.md
    Update Chrome casting documentation with Java example       

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

    • Updated Java code example reference for Chrome casting.
    +1/-1     
    chrome.ja.md
    Update Chrome casting documentation with Java example       

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

    • Updated Java code example reference for Chrome casting.
    +1/-1     
    chrome.pt-br.md
    Update Chrome casting documentation with Java example       

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

    • Updated Java code example reference for Chrome casting.
    +1/-1     
    chrome.zh-cn.md
    Update Chrome casting documentation with Java example       

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

    • Updated Java code example reference for Chrome casting.
    +1/-1     
    edge.en.md
    Update Edge casting documentation with Java example           

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

    • Updated Java code example reference for Edge casting.
    +1/-1     
    edge.ja.md
    Update Edge casting documentation with Java example           

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

    • Updated Java code example reference for Edge casting.
    +1/-1     
    edge.pt-br.md
    Update Edge casting documentation with Java example           

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

    • Updated Java code example reference for Edge casting.
    +1/-1     
    edge.zh-cn.md
    Update Edge casting documentation with Java example           

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

    • Updated Java code example reference for Edge casting.
    +1/-1     

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

    Copy link

    netlify bot commented Nov 25, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit 0472752

    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 Leak
    The driver is not properly closed in case of exceptions during cast operations. Consider using try-finally or try-with-resources to ensure driver cleanup.

    Resource Leak
    The driver is not properly closed in case of exceptions during cast operations. Consider using try-finally or try-with-resources to ensure driver cleanup.

    Error Handling
    No error handling for potential failures during cast operations like invalid sink name or casting failures.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Ensure proper resource cleanup by using try-finally block

    Add try-finally block to ensure driver is always quit, even if an exception occurs
    during casting operations.

    examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java [228-237]

     ChromeDriver driver = new ChromeDriver();
    -
    -List<Map<String, String>> sinks = driver.getCastSinks();
    -if (!sinks.isEmpty()) {
    -  String sinkName = sinks.get(0).get("name");
    -  driver.startTabMirroring(sinkName);
    -  driver.stopCasting(sinkName);
    +try {
    +  List<Map<String, String>> sinks = driver.getCastSinks();
    +  if (!sinks.isEmpty()) {
    +    String sinkName = sinks.get(0).get("name");
    +    driver.startTabMirroring(sinkName);
    +    driver.stopCasting(sinkName);
    +  }
    +} finally {
    +  driver.quit();
     }
     
    -driver.quit();
    -
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: This is a crucial improvement for resource management, ensuring the WebDriver is properly closed even if exceptions occur during casting operations, preventing resource leaks.

    9
    Possible issue
    Add null checks when accessing Map values to prevent runtime exceptions

    Add error handling for potential null values when accessing the sink name from the
    Map to prevent NullPointerException.

    examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java [232]

    -String sinkName = sinks.get(0).get("name");
    +Map<String, String> sink = sinks.get(0);
    +if (sink != null && sink.get("name") != null) {
    +    String sinkName = sink.get("name");
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a critical issue by preventing potential NullPointerException during Map value access, which could cause runtime failures in production.

    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 3afb742 into SeleniumHQ:trunk Nov 27, 2024
    9 checks passed
    @navin772 navin772 deleted the java_casting branch November 27, 2024 17:06
    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