Skip to content

[py]: add docs for get_log for chrome and edge #2074

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 2 commits into from
Nov 26, 2024

Conversation

navin772
Copy link
Member

@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 get_log for chrome and edge in python

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 tests for retrieving browser logs in both Chrome and Edge using Python.
  • Updated documentation for Chrome and Edge to include Python examples for the get_log method.
  • Ensured documentation is updated across multiple languages including English, Japanese, Portuguese, and Chinese.

Changes walkthrough 📝

Relevant files
Tests
2 files
test_chrome.py
Add test for retrieving Chrome browser logs                           

examples/python/tests/browsers/test_chrome.py

  • Added a test for retrieving browser logs in Chrome.
  • Asserts presence of specific log messages.
  • +12/-0   
    test_edge.py
    Add test for retrieving Edge browser logs                               

    examples/python/tests/browsers/test_edge.py

  • Added a test for retrieving browser logs in Edge.
  • Asserts presence of specific log messages.
  • +12/-0   
    Documentation
    8 files
    chrome.en.md
    Add Python example for Chrome `get_log` documentation       

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

    • Added Python code example for get_log in Chrome documentation.
    +3/-3     
    chrome.ja.md
    Add Python example for Chrome `get_log` documentation       

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

    • Added Python code example for get_log in Chrome documentation.
    +3/-3     
    chrome.pt-br.md
    Add Python example for Chrome `get_log` documentation       

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

    • Added Python code example for get_log in Chrome documentation.
    +3/-3     
    chrome.zh-cn.md
    Add Python example for Chrome `get_log` documentation       

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

    • Added Python code example for get_log in Chrome documentation.
    +3/-3     
    edge.en.md
    Add Python example for Edge `get_log` documentation           

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

    • Added Python code example for get_log in Edge documentation.
    +3/-3     
    edge.ja.md
    Add Python example for Edge `get_log` documentation           

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

    • Added Python code example for get_log in Edge documentation.
    +3/-3     
    edge.pt-br.md
    Add Python example for Edge `get_log` documentation           

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

    • Added Python code example for get_log in Edge documentation.
    +3/-3     
    edge.zh-cn.md
    Add Python example for Edge `get_log` documentation           

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

    • Added Python code example for get_log in Edge documentation.
    +3/-3     

    💡 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 0db2b53

    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 Reliability
    The test assumes there will be an 'Uncaught TypeError' in the logs when visiting selenium.dev. This assumption may be fragile and could lead to flaky tests if the site changes.

    Test Reliability
    The test assumes there will be an 'Uncaught TypeError' in the logs when visiting selenium.dev. This assumption may be fragile and could lead to flaky tests if the site changes.

    Resource Cleanup
    The driver.quit() call should be in a finally block to ensure cleanup even if the test fails

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Ensure test reliability by explicitly generating the log message to be verified instead of relying on undefined behavior

    The test assumes there will be an "Uncaught TypeError" in the logs without
    explicitly triggering one. This makes the test unreliable. Instead, execute
    JavaScript that will generate a known error to test log capture.

    examples/python/tests/browsers/test_chrome.py [184-186]

     driver.get("https://www.selenium.dev/")
    +driver.execute_script("console.error('Test Error Message')")
     logs = driver.get_log("browser")
    -assert any("Uncaught TypeError" in log['message'] for log in logs), "No matching log message found."
    +assert any("Test Error Message" in log['message'] for log in logs), "No matching log message found."
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: The suggestion significantly improves test reliability by explicitly generating the log message to verify instead of relying on random TypeError occurrences. This makes the test deterministic and prevents flaky behavior.

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

    Add cleanup in a try-finally block to ensure the driver is always quit, even if the
    test fails.

    examples/python/tests/browsers/test_chrome.py [181-190]

     def test_get_browser_logs():
         driver = webdriver.Chrome()
    -    driver.get("https://www.selenium.dev/")
    -    logs = driver.get_log("browser")
    -    assert any("Uncaught TypeError" in log['message'] for log in logs), "No matching log message found."
    -    driver.quit()
    +    try:
    +        driver.get("https://www.selenium.dev/")
    +        logs = driver.get_log("browser")
    +        assert any("Uncaught TypeError" in log['message'] for log in logs), "No matching log message found."
    +    finally:
    +        driver.quit()
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion ensures proper cleanup of browser resources by wrapping driver operations in a try-finally block, preventing resource leaks even if the test fails. This is a critical best practice for WebDriver test reliability.

    8

    💡 Need additional feedback ? start a PR chat

    @harsha509 harsha509 merged commit 313d31c into SeleniumHQ:trunk Nov 26, 2024
    9 checks passed
    selenium-ci added a commit that referenced this pull request Nov 26, 2024
    add docs for `get_log` in python for chrome and edge
    
    Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com> 313d31c
    @navin772 navin772 deleted the py_get_log branch November 27, 2024 03:24
    @navin772 navin772 restored the py_get_log branch November 27, 2024 03:45
    @navin772 navin772 deleted the py_get_log branch November 27, 2024 03:45
    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