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

[py]: add example and docs for casting in edge and chrome #2072

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

navin772
Copy link
Contributor

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

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 new tests for casting features in both Chrome and Edge browsers using Selenium WebDriver.
  • Updated documentation to include Python code examples for casting in multiple languages (English, Japanese, Portuguese, Chinese).
  • Utilized pytest to handle scenarios where no Cast sinks are available.

Changes walkthrough 📝

Relevant files
Tests
2 files
test_chrome.py
Add casting feature test for Chrome browser                           

examples/python/tests/browsers/test_chrome.py

  • Added a new test test_cast_features for Chrome.
  • Utilized webdriver.Chrome() to test casting features.
  • Implemented logic to handle no available Cast sinks.
  • +16/-1   
    test_edge.py
    Add casting feature test for Edge browser                               

    examples/python/tests/browsers/test_edge.py

  • Added a new test test_cast_features for Edge.
  • Utilized webdriver.Edge() to test casting features.
  • Implemented logic to handle no available Cast sinks.
  • +16/-1   
    Documentation
    8 files
    chrome.en.md
    Update Chrome documentation with Python casting example   

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

    • Updated Python tab with a code example for casting.
    +3/-3     
    chrome.ja.md
    Update Chrome documentation with Python casting example in Japanese

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

    • Updated Python tab with a code example for casting.
    +3/-3     
    chrome.pt-br.md
    Update Chrome documentation with Python casting example in Portuguese

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

    • Updated Python tab with a code example for casting.
    +3/-3     
    chrome.zh-cn.md
    Update Chrome documentation with Python casting example in Chinese

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

    • Updated Python tab with a code example for casting.
    +3/-4     
    edge.en.md
    Update Edge documentation with Python casting example       

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

    • Updated Python tab with a code example for casting.
    +3/-3     
    edge.ja.md
    Update Edge documentation with Python casting example in Japanese

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

    • Updated Python tab with a code example for casting.
    +3/-3     
    edge.pt-br.md
    Update Edge documentation with Python casting example in Portuguese

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

    • Updated Python tab with a code example for casting.
    +3/-3     
    edge.zh-cn.md
    Update Edge documentation with Python casting example in Chinese

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

    • Updated Python tab with a code example for casting.
    +3/-3     

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

    Copy link

    netlify bot commented Nov 22, 2024

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit ad4d7e6

    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 Management
    The driver is created outside the try block but closed inside finally. Consider using a context manager (with statement) for better resource management.

    Resource Management
    The driver is created outside the try block but closed inside finally. Consider using a context manager (with statement) for better resource management.

    Error Handling
    The test assumes get_sinks() will always succeed. Consider adding error handling for potential API failures.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Add timeout parameter to prevent indefinite waiting during network operations

    Add a timeout when getting cast sinks to prevent indefinite waiting if the system is
    slow to respond or has connectivity issues.

    examples/python/tests/browsers/test_chrome.py [170-172]

    -sinks = driver.get_sinks()
    +sinks = driver.get_sinks(timeout=10)  # 10 second timeout
     if sinks:
         sink_name = sinks[0]['name']
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a timeout is crucial for preventing test hangs in network operations, which could significantly impact test reliability and execution time in CI/CD pipelines.

    8
    Possible issue
    Validate operation success before proceeding with subsequent actions

    Verify that casting was successful before attempting to stop it, as the start
    operation might fail silently.

    examples/python/tests/browsers/test_chrome.py [173-174]

    -driver.start_tab_mirroring(sink_name)
    -driver.stop_casting(sink_name)
    +cast_result = driver.start_tab_mirroring(sink_name)
    +if cast_result:  # Verify casting started successfully
    +    driver.stop_casting(sink_name)
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Verifying the success of the casting operation before attempting to stop it prevents potential issues from silent failures and improves test robustness.

    7
    Add defensive programming to handle malformed data structures

    Add error handling for potential exceptions when accessing the sink name to prevent
    KeyError if the sink object is malformed.

    examples/python/tests/browsers/test_chrome.py [171-172]

    -if sinks:
    +if sinks and isinstance(sinks[0], dict) and 'name' in sinks[0]:
         sink_name = sinks[0]['name']
    +else:
    +    pytest.skip("Invalid sink data structure")
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Adding validation for the sink data structure helps prevent runtime errors and provides clearer feedback when the sink data is malformed.

    6

    💡 Need additional feedback ? start a PR chat

    @navin772
    Copy link
    Contributor Author

    The safari stable tests are failing due to an issue in selenium - SeleniumHQ/selenium#14698 which should be fixed once a minor release is done.

    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 6c18cac into SeleniumHQ:trunk Nov 22, 2024
    8 of 9 checks passed
    @navin772 navin772 deleted the py-casting branch November 22, 2024 17:22
    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