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

Correct Webdriver HTTP Client in Python examples #2045

Merged
merged 1 commit into from
Nov 6, 2024
Merged

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented Nov 6, 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

Motivation and Context

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


Description

  • Removed the @pytest.mark.sanity decorator from the test functions test_start_remote_with_client_config and test_start_remote_ignore_certs, which may have been used for categorizing tests.
  • Corrected the structure of the init_args_for_pool_manager dictionary in the test_start_remote_with_client_config function to ensure proper initialization of retries and timeout parameters.

Changes walkthrough 📝

Relevant files
Tests
test_http_client.py
Update test configuration and remove sanity mark                 

examples/python/tests/drivers/test_http_client.py

  • Removed @pytest.mark.sanity decorator from tests.
  • Corrected the dictionary structure for init_args_for_pool_manager.
  • +2/-3     

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

    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

    Incorrect Dictionary Structure
    The structure of the init_args_for_pool_manager dictionary in the test_start_remote_with_client_config function has been changed, but it may not be correct. The new structure creates a nested dictionary, which might not be the intended behavior.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Remove redundant nesting in dictionary argument

    Remove the redundant nesting of "init_args_for_pool_manager" in the dictionary. The
    key is already specified as a parameter name, so it shouldn't be repeated in the
    dictionary.

    examples/python/tests/drivers/test_http_client.py [16-21]

     client_config = ClientConfig(remote_server_addr=grid_server,
                                  proxy=proxy,
    -                             init_args_for_pool_manager={
    -                                 "init_args_for_pool_manager": {"retries": retries, "timeout": timeout}},
    +                             init_args_for_pool_manager={"retries": retries, "timeout": timeout},
                                  ca_certs=_get_resource_path("tls.crt"),
                                  username="admin", password="myStrongPassword")
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: The suggestion correctly identifies a critical issue in the PR. The redundant nesting of "init_args_for_pool_manager" would likely cause runtime errors or unexpected behavior. Removing this nesting is crucial for the correct functioning of the ClientConfig initialization.

    9

    💡 Need additional feedback ? start a PR chat

    Copy link

    netlify bot commented Nov 6, 2024

    Deploy Preview for selenium-dev ready!

    Name Link
    🔨 Latest commit 7c83749
    🔍 Latest deploy log https://app.netlify.com/sites/selenium-dev/deploys/672b107606c67b0008193ef3
    😎 Deploy Preview https://deploy-preview-2045--selenium-dev.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link
    Contributor

    CI Failure Feedback 🧐

    Action: tests (macos, stable)

    Failed stage: Run tests [❌]

    Failed test name: test_basic_options

    Failure summary:

    The action failed due to errors in two tests related to the Safari WebDriver:

  • test_basic_options and test_enable_logging both failed with a TypeError.
  • The error message indicates that the init method of SafariRemoteConnection is missing a required
    positional argument: remote_server_addr.
  • This suggests a misconfiguration or an issue in the code where the SafariRemoteConnection is being
    instantiated without providing the necessary remote_server_addr argument.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  macOS
    ...
    
    152:  Installing collected packages: pip
    153:  Successfully installed pip-24.3.1
    154:  Install OpenSSL certificates
    155:  Collecting certifi
    156:  Using cached certifi-2024.8.30-py3-none-any.whl.metadata (2.2 kB)
    157:  Using cached certifi-2024.8.30-py3-none-any.whl (167 kB)
    158:  Installing collected packages: certifi
    159:  Successfully installed certifi-2024.8.30
    160:  ##[error][notice] A new release of pip is available: 21.1.1 -> 24.3.1
    ...
    
    316:  timeout_minutes: 40
    317:  max_attempts: 3
    318:  command: cd examples/python
    319:  pytest
    320:  
    321:  retry_wait_seconds: 10
    322:  polling_interval_seconds: 1
    323:  warning_on_retry: true
    324:  continue_on_error: false
    ...
    
    361:  tests/elements/test_file_upload.py .                                     [ 77%]
    362:  tests/interactions/test_alerts.py ...                                    [ 79%]
    363:  tests/interactions/test_print_options.py .......                         [ 84%]
    364:  tests/interactions/test_prints_page.py .                                 [ 85%]
    365:  tests/interactions/test_virtual_authenticator.py ..........              [ 93%]
    366:  tests/support/test_select_list.py ...                                    [ 95%]
    367:  tests/troubleshooting/test_logging.py .                                  [ 96%]
    368:  tests/waits/test_waits.py .....                                          [100%]
    369:  =================================== FAILURES ===================================
    370:  ______________________________ test_basic_options ______________________________
    371:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    372:  def test_basic_options():
    373:  options = webdriver.SafariOptions()
    374:  >       driver = webdriver.Safari(options=options)
    375:  tests/browsers/test_safari.py:10: 
    376:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    377:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x103844190>
    ...
    
    397:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    398:  if not self.service.reuse_service:
    399:  self.service.start()
    400:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    401:  >       executor = SafariRemoteConnection(
    402:  ignore_proxy=options._ignore_local_proxy,
    403:  client_config=client_config,
    404:  )
    405:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    406:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    407:  _____________________________ test_enable_logging ______________________________
    408:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    409:  def test_enable_logging():
    410:  service = webdriver.SafariService(service_args=["--diagnose"])
    411:  >       driver = webdriver.Safari(service=service)
    412:  tests/browsers/test_safari.py:19: 
    413:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    414:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x103872280>
    ...
    
    434:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    435:  if not self.service.reuse_service:
    436:  self.service.start()
    437:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    438:  >       executor = SafariRemoteConnection(
    439:  ignore_proxy=options._ignore_local_proxy,
    440:  client_config=client_config,
    441:  )
    442:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    443:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    ...
    
    451:  tests/bidi/test_bidi_logging.py:30
    452:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/bidi/test_bidi_logging.py:30: PytestUnknownMarkWarning: Unknown pytest.mark.driver_type - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    453:  @pytest.mark.driver_type("bidi")
    454:  tests/bidi/test_bidi_logging.py:42
    455:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/bidi/test_bidi_logging.py:42: PytestUnknownMarkWarning: Unknown pytest.mark.driver_type - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    456:  @pytest.mark.driver_type("bidi")
    457:  -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    458:  =========================== short test summary info ============================
    459:  FAILED tests/browsers/test_safari.py::test_basic_options - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    460:  FAILED tests/browsers/test_safari.py::test_enable_logging - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    461:  ======= 2 failed, 124 passed, 7 skipped, 4 warnings in 358.35s (0:05:58) =======
    462:  ##[warning]Attempt 1 failed. Reason: Child_process exited with error code 1
    ...
    
    487:  tests/elements/test_file_upload.py .                                     [ 77%]
    488:  tests/interactions/test_alerts.py ...                                    [ 79%]
    489:  tests/interactions/test_print_options.py .......                         [ 84%]
    490:  tests/interactions/test_prints_page.py .                                 [ 85%]
    491:  tests/interactions/test_virtual_authenticator.py ..........              [ 93%]
    492:  tests/support/test_select_list.py ...                                    [ 95%]
    493:  tests/troubleshooting/test_logging.py .                                  [ 96%]
    494:  tests/waits/test_waits.py .....                                          [100%]
    495:  =================================== FAILURES ===================================
    496:  ______________________________ test_basic_options ______________________________
    497:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    498:  def test_basic_options():
    499:  options = webdriver.SafariOptions()
    500:  >       driver = webdriver.Safari(options=options)
    501:  tests/browsers/test_safari.py:10: 
    502:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    503:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x1051e80a0>
    ...
    
    523:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    524:  if not self.service.reuse_service:
    525:  self.service.start()
    526:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    527:  >       executor = SafariRemoteConnection(
    528:  ignore_proxy=options._ignore_local_proxy,
    529:  client_config=client_config,
    530:  )
    531:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    532:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    533:  _____________________________ test_enable_logging ______________________________
    534:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    535:  def test_enable_logging():
    536:  service = webdriver.SafariService(service_args=["--diagnose"])
    537:  >       driver = webdriver.Safari(service=service)
    538:  tests/browsers/test_safari.py:19: 
    539:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    540:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x1051ab670>
    ...
    
    560:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    561:  if not self.service.reuse_service:
    562:  self.service.start()
    563:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    564:  >       executor = SafariRemoteConnection(
    565:  ignore_proxy=options._ignore_local_proxy,
    566:  client_config=client_config,
    567:  )
    568:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    569:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    ...
    
    577:  tests/bidi/test_bidi_logging.py:30
    578:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/bidi/test_bidi_logging.py:30: PytestUnknownMarkWarning: Unknown pytest.mark.driver_type - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    579:  @pytest.mark.driver_type("bidi")
    580:  tests/bidi/test_bidi_logging.py:42
    581:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/bidi/test_bidi_logging.py:42: PytestUnknownMarkWarning: Unknown pytest.mark.driver_type - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    582:  @pytest.mark.driver_type("bidi")
    583:  -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    584:  =========================== short test summary info ============================
    585:  FAILED tests/browsers/test_safari.py::test_basic_options - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    586:  FAILED tests/browsers/test_safari.py::test_enable_logging - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    587:  ======= 2 failed, 124 passed, 7 skipped, 4 warnings in 518.10s (0:08:38) =======
    588:  ##[warning]Attempt 2 failed. Reason: Child_process exited with error code 1
    ...
    
    613:  tests/elements/test_file_upload.py .                                     [ 77%]
    614:  tests/interactions/test_alerts.py ...                                    [ 79%]
    615:  tests/interactions/test_print_options.py .......                         [ 84%]
    616:  tests/interactions/test_prints_page.py .                                 [ 85%]
    617:  tests/interactions/test_virtual_authenticator.py ..........              [ 93%]
    618:  tests/support/test_select_list.py ...                                    [ 95%]
    619:  tests/troubleshooting/test_logging.py .                                  [ 96%]
    620:  tests/waits/test_waits.py .....                                          [100%]
    621:  =================================== FAILURES ===================================
    622:  ______________________________ test_basic_options ______________________________
    623:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    624:  def test_basic_options():
    625:  options = webdriver.SafariOptions()
    626:  >       driver = webdriver.Safari(options=options)
    627:  tests/browsers/test_safari.py:10: 
    628:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    629:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x107401340>
    ...
    
    649:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    650:  if not self.service.reuse_service:
    651:  self.service.start()
    652:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    653:  >       executor = SafariRemoteConnection(
    654:  ignore_proxy=options._ignore_local_proxy,
    655:  client_config=client_config,
    656:  )
    657:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    658:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    659:  _____________________________ test_enable_logging ______________________________
    660:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    661:  def test_enable_logging():
    662:  service = webdriver.SafariService(service_args=["--diagnose"])
    663:  >       driver = webdriver.Safari(service=service)
    664:  tests/browsers/test_safari.py:19: 
    665:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    666:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x1073c0f10>
    ...
    
    686:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    687:  if not self.service.reuse_service:
    688:  self.service.start()
    689:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    690:  >       executor = SafariRemoteConnection(
    691:  ignore_proxy=options._ignore_local_proxy,
    692:  client_config=client_config,
    693:  )
    694:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    695:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    ...
    
    703:  tests/bidi/test_bidi_logging.py:30
    704:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/bidi/test_bidi_logging.py:30: PytestUnknownMarkWarning: Unknown pytest.mark.driver_type - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    705:  @pytest.mark.driver_type("bidi")
    706:  tests/bidi/test_bidi_logging.py:42
    707:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/bidi/test_bidi_logging.py:42: PytestUnknownMarkWarning: Unknown pytest.mark.driver_type - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    708:  @pytest.mark.driver_type("bidi")
    709:  -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    710:  =========================== short test summary info ============================
    711:  FAILED tests/browsers/test_safari.py::test_basic_options - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    712:  FAILED tests/browsers/test_safari.py::test_enable_logging - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    713:  ======= 2 failed, 124 passed, 7 skipped, 4 warnings in 393.86s (0:06:33) =======
    714:  ##[error]Final attempt failed. Child_process exited with error code 1
    

    ✨ CI feedback usage guide:

    The CI feedback tool (/checks) automatically triggers when a PR has a failed check.
    The tool analyzes the failed checks and provides several feedbacks:

    • Failed stage
    • Failed test name
    • Failure summary
    • Relevant error logs

    In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:

    /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"
    

    where {repo_name} is the name of the repository, {run_number} is the run number of the failed check, and {job_number} is the job number of the failed check.

    Configuration options

    • enable_auto_checks_feedback - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
    • excluded_checks_list - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
    • enable_help_text - if set to true, the tool will provide a help message with the feedback. Default is true.
    • persistent_comment - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
    • final_update_message - if persistent_comment is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

    See more information about the checks tool in the docs.

    @VietND96 VietND96 merged commit 41b6d6b into trunk Nov 6, 2024
    11 of 12 checks passed
    @VietND96 VietND96 deleted the py-examples branch November 6, 2024 07:22
    selenium-ci added a commit that referenced this pull request Nov 6, 2024
    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.

    1 participant