Skip to content

[java]: docs for set context in firefox #2068

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 1 commit into from
Nov 20, 2024

Conversation

navin772
Copy link
Member

@navin772 navin772 commented Nov 20, 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

Java docs for set context in firefox

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 a new test method setContext in FirefoxTest.java to test Firefox context switching using the HasContext interface.
  • Updated documentation for Firefox browser in multiple languages (English, Japanese, Portuguese, Chinese) to improve Java code example formatting by using gh-codeblock.

Changes walkthrough 📝

Relevant files
Tests
FirefoxTest.java
Add test for Firefox context switching in Java                     

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

  • Added a new test method setContext to test Firefox context switching.
  • Used HasContext interface to set and verify the context.
  • Ensured the context is set to 'chrome' and verified.
  • +21/-5   
    Documentation
    firefox.en.md
    Update Java code example formatting in English docs           

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

  • Updated Java code example to use gh-codeblock for better clarity.
  • +1/-1     
    firefox.ja.md
    Update Java code example formatting in Japanese docs         

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

  • Updated Java code example to use gh-codeblock for better clarity.
  • +1/-1     
    firefox.pt-br.md
    Update Java code example formatting in Portuguese docs     

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

  • Updated Java code example to use gh-codeblock for better clarity.
  • +1/-1     
    firefox.zh-cn.md
    Update Java code example formatting in Chinese docs           

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

  • Updated Java code example to use gh-codeblock for better clarity.
  • +1/-1     

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

    Copy link

    netlify bot commented Nov 20, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit 2bc79b7

    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

    Test Validation
    The test verifies the context is 'chrome' but doesn't verify if the console.log command actually executed successfully

    Error Handling
    The test should handle potential exceptions that could occur during context switching or script execution

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

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

    Add a try-finally block to ensure driver is always quit even if assertions or script
    execution fail.

    examples/java/src/test/java/dev/selenium/browsers/FirefoxTest.java [195-206]

     driver = startFirefoxDriver();
    +try {
    +    ((HasContext) driver).setContext(FirefoxCommandContext.CHROME);
    +    driver.executeScript("console.log('Inside Chrome context');");
     
    -((HasContext) driver).setContext(FirefoxCommandContext.CHROME);
    -driver.executeScript("console.log('Inside Chrome context');");
    +    Assertions.assertEquals(
    +            FirefoxCommandContext.CHROME, ((HasContext) driver).getContext(),
    +            "The context should be 'chrome'"
    +    );
    +} finally {
    +    driver.quit();
    +}
     
    -Assertions.assertEquals(
    -        FirefoxCommandContext.CHROME, ((HasContext) driver).getContext(),
    -        "The context should be 'chrome'"
    -);
    -
    -driver.quit();
    -
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a try-finally block is a crucial improvement for resource management, ensuring the WebDriver is properly closed even if an exception occurs during test execution, preventing resource leaks and hanging browser processes.

    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 cb7d8ae into SeleniumHQ:trunk Nov 20, 2024
    9 checks passed
    selenium-ci added a commit that referenced this pull request Nov 20, 2024
    @navin772 navin772 deleted the java-setContext branch November 20, 2024 19:01
    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