seleniumhq.github.io icon indicating copy to clipboard operation
seleniumhq.github.io copied to clipboard

Updated Python Examples for Options

Open shbenzer opened this issue 1 year ago • 3 comments

User description

Updated Python examples in Browser Options

Description

added examples to test_options.py made examples more consistent with other language examples updated all translations of index.mds

Motivation and Context

Issue #1983

Types of changes

  • [ ] Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • [x] 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

  • [x] I have read the contributing document.
  • [x] I have used hugo to render the site/docs locally and I am sure it works.

PR Type

Tests, Documentation


Description

  • Added new Python test cases for browser options including browser name, version, and platform name.
  • Updated existing Python test cases to improve consistency and ensure all tests navigate to and quit from the Selenium website.
  • Updated documentation in multiple languages (English, Japanese, Portuguese, Chinese) to reflect new line numbers for Python code examples.
  • Ensured consistency across different language examples in the documentation.

Changes walkthrough 📝

Relevant files
Tests
test_options.py
Enhance and unify Python test examples for browser options

examples/python/tests/drivers/test_options.py

  • Added new test cases for browser name, version, and platform name.
  • Updated existing test cases to improve consistency.
  • Changed FirefoxOptions to ChromeOptions in test_set_window_rect.
  • Ensured all tests navigate to and quit from the Selenium website.
  • +31/-25 
    Documentation
    options.en.md
    Update English documentation with new Python example references

    website_and_docs/content/documentation/webdriver/drivers/options.en.md

  • Updated Python code example references to new line numbers.
  • Ensured consistency with updated Python test examples.
  • +14/-14 
    options.ja.md
    Update Japanese documentation with new Python example references

    website_and_docs/content/documentation/webdriver/drivers/options.ja.md

  • Updated Python code example references to new line numbers.
  • Ensured consistency with updated Python test examples.
  • +14/-14 
    options.pt-br.md
    Update Portuguese documentation with new Python example references

    website_and_docs/content/documentation/webdriver/drivers/options.pt-br.md

  • Updated Python code example references to new line numbers.
  • Ensured consistency with updated Python test examples.
  • +14/-14 
    options.zh-cn.md
    Update Chinese documentation with new Python example references

    website_and_docs/content/documentation/webdriver/drivers/options.zh-cn.md

  • Updated Python code example references to new line numbers.
  • Ensured consistency with updated Python test examples.
  • +14/-14 

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

    shbenzer avatar Oct 22 '24 16:10 shbenzer

    Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    Latest commit 69de78a9d4a9dc0638e2ffdfccd27220b8415ba0

    netlify[bot] avatar Oct 22 '24 16:10 netlify[bot]

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis 🔶

    1983 - Partially compliant

    Fully compliant requirements:

    • Update code examples in the Browser Options section to be consistent across programming languages
    • Ensure Java example creates an options object and inspects the browser name attribute
    • Make Python examples consistent with Java example
    • Ensure consistency in the pageLoadStrategy section across all language examples

    Not compliant requirements:

    • Ruby examples are not updated in this PR
    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Consistency Check
    Verify that the new Python examples are consistent with Java examples, especially for browser name, version, and platform name.

    Documentation Update
    Ensure that the updated line numbers in the documentation accurately reflect the changes made in the Python test file.

    qodo-code-review[bot] avatar Oct 22 '24 16:10 qodo-code-review[bot]

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Enhancement
    Use fixtures and parameterization to reduce code duplication and improve test maintainability

    Extract the common setup and teardown code into fixture functions to reduce code
    duplication across test cases.

    examples/python/tests/drivers/test_options.py [6-11]

    -def test_page_load_strategy_normal():
    +import pytest
    +
    [email protected]
    +def chrome_driver(request):
         options = webdriver.ChromeOptions()
    -    options.page_load_strategy = 'normal'
    +    options.page_load_strategy = request.param
         driver = webdriver.Chrome(options=options)
    -    driver.get("https://www.selenium.dev/")
    +    yield driver
         driver.quit()
     
    [email protected]('chrome_driver', ['normal', 'eager', 'none'], indirect=True)
    +def test_page_load_strategy(chrome_driver):
    +    chrome_driver.get("https://www.selenium.dev/")
    +
    
    • [ ] Apply this suggestion <!-- /improve --apply_suggestion=0 -->
    Suggestion importance[1-10]: 9

    Why: The suggestion significantly reduces code duplication and enhances maintainability by using pytest fixtures and parameterization, which is a best practice in test design.

    9
    Add assertions to verify that options are correctly applied to the driver

    Add assertions to verify that the options are correctly set and applied to the
    driver.

    examples/python/tests/drivers/test_options.py [78-83]

     def test_set_browser_name():
         options = webdriver.ChromeOptions()
         assert options.capabilities['browserName'] == 'chrome'
         driver = webdriver.Chrome(options=options)
    +    assert driver.capabilities['browserName'] == 'chrome'
         driver.get("https://www.selenium.dev/")
         driver.quit()
    
    • [ ] Apply this suggestion <!-- /improve --apply_suggestion=1 -->
    Suggestion importance[1-10]: 7

    Why: Adding assertions to verify that options are correctly applied enhances test reliability by ensuring that the driver is configured as expected, which is crucial for test accuracy.

    7
    Add error handling and logging to improve test robustness and debuggability

    Consider adding error handling and logging to improve the robustness and
    debuggability of the tests.

    examples/python/tests/drivers/test_options.py [71-76]

    +import logging
    +
     def test_proxy():
         options = webdriver.ChromeOptions()
         options.proxy = Proxy({ 'proxyType': ProxyType.MANUAL, 'httpProxy' : 'http.proxy:1234'})
    -    driver = webdriver.Chrome(options=options)
    -    driver.get("https://www.selenium.dev/")
    -    driver.quit()
    +    try:
    +        driver = webdriver.Chrome(options=options)
    +        driver.get("https://www.selenium.dev/")
    +    except Exception as e:
    +        logging.error(f"Error occurred: {e}")
    +        raise
    +    finally:
    +        if 'driver' in locals():
    +            driver.quit()
    
    • [ ] Apply this suggestion <!-- /improve --apply_suggestion=2 -->
    Suggestion importance[1-10]: 6

    Why: While adding error handling and logging can improve robustness and debuggability, the implementation is somewhat verbose for a test context, which slightly reduces its impact.

    6
    Best practice
    Use a context manager to ensure proper resource management and exception handling

    Consider using a context manager (with statement) to ensure the driver is properly
    closed, even if an exception occurs during the test.

    examples/python/tests/drivers/test_options.py [7-11]

     options = webdriver.ChromeOptions()
     options.page_load_strategy = 'normal'
    -driver = webdriver.Chrome(options=options)
    -driver.get("https://www.selenium.dev/")
    -driver.quit()
    +with webdriver.Chrome(options=options) as driver:
    +    driver.get("https://www.selenium.dev/")
    
    • [ ] Apply this suggestion <!-- /improve --apply_suggestion=3 -->
    Suggestion importance[1-10]: 8

    Why: This suggestion improves resource management by ensuring the driver is closed properly even if an exception occurs, enhancing the robustness and reliability of the tests.

    8

    💡 Need additional feedback ? start a PR chat

    qodo-code-review[bot] avatar Oct 22 '24 16:10 qodo-code-review[bot]

    Failure has nothing to do with submitted code - though I do see it occasionally on other PRs. Do we know why this test fails on Ubuntu? tests/actions_api/test_mouse.py::test_move_by_offset_from_viewport_origin_ab @harsha509 @A1exKH

    shbenzer avatar Oct 28 '24 18:10 shbenzer

    tests/actions_api/test_mouse.py::test_move_by_offset_from_viewport_origin_ab

    Looks like a flaky one..!

    Looking into it!

    harsha509 avatar Oct 28 '24 18:10 harsha509