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] Fix TypeError when init Safari webdriver #14699

Merged
merged 3 commits into from
Nov 1, 2024
Merged

[py] Fix TypeError when init Safari webdriver #14699

merged 3 commits into from
Nov 1, 2024

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented Nov 1, 2024

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix, Tests


Description

  • Fixed a TypeError in the Safari WebDriver initialization by removing the ClientConfig and adjusting the SafariRemoteConnection setup.
  • Added a new job in the CI workflow to run Safari tests on macOS, ensuring better test coverage for Safari.
  • Marked the test_launch_safari_with_legacy_flag as skipped, indicating it needs updates.

Changes walkthrough 📝

Relevant files
Bug fix
webdriver.py
Fix TypeError by adjusting SafariRemoteConnection initialization

py/selenium/webdriver/safari/webdriver.py

  • Removed ClientConfig import and usage.
  • Modified SafariRemoteConnection initialization to directly use
    parameters.
  • +2/-3     
    Tests
    launcher_tests.py
    Mark Safari legacy flag test to be skipped                             

    py/test/selenium/webdriver/safari/launcher_tests.py

    • Added a skip marker to test_launch_safari_with_legacy_flag.
    +1/-0     
    ci-python.yml
    Add Safari tests to CI workflow                                                   

    .github/workflows/ci-python.yml

  • Added a new job for Safari tests in the CI workflow.
  • Configured Safari tests to run on macOS.
  • +12/-0   

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

    Copy link
    Contributor

    qodo-merge-pro bot commented Nov 1, 2024

    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

    Parameter Change
    The SafariRemoteConnection initialization has been modified to directly use parameters instead of ClientConfig. Verify that all necessary parameters are correctly passed and that this change doesn't affect the functionality.

    Skipped Test
    The test_launch_safari_with_legacy_flag has been marked as skipped. Ensure that this test is updated or replaced to maintain proper test coverage for the Safari launcher.

    CI Configuration
    A new job for Safari tests has been added to the CI workflow. Verify that the configuration is correct and that it will run the appropriate tests on the correct environment.

    Copy link
    Contributor

    qodo-merge-pro bot commented Nov 1, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a default value for the keep_alive parameter to maintain backwards compatibility

    Consider adding a default value for the keep_alive parameter in the
    SafariRemoteConnection initialization to maintain backwards compatibility and
    prevent potential TypeErrors.

    py/selenium/webdriver/safari/webdriver.py [53-57]

     executor = SafariRemoteConnection(
         remote_server_addr=self.service.service_url,
    -    keep_alive=keep_alive,
    +    keep_alive=keep_alive if keep_alive is not None else True,
         ignore_proxy=options._ignore_local_proxy,
     )
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a default value for the keep_alive parameter is a practical suggestion to maintain backwards compatibility and prevent potential TypeErrors if the parameter is not provided. This change enhances the robustness of the code.

    8
    Best practice
    Add a timeout for Safari tests in the CI workflow to prevent potential pipeline blockages

    Consider adding a timeout for the Safari tests to prevent potential hanging or
    long-running tests from blocking the CI pipeline.

    .github/workflows/ci-python.yml [90-100]

     safari-tests:
       name: Safari Tests
       needs: build
       uses: ./.github/workflows/bazel.yml
       with:
         name: Integration Tests (safari)
         browser: safari
         os: macos
         cache-key: py-safari
         run: |
    -      bazel test --local_test_jobs 1 --flaky_test_attempts 3 //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py
    +      bazel test --local_test_jobs 1 --flaky_test_attempts 3 --test_timeout 300 //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding a timeout to the Safari tests in the CI workflow is a sensible practice to prevent long-running tests from blocking the pipeline. This suggestion improves the reliability and efficiency of the CI process.

    7
    Enhancement
    Update the test case to reflect changes in the Safari webdriver implementation instead of skipping it

    Instead of skipping the test, consider updating it to reflect the changes made in
    the Safari webdriver implementation.

    py/test/selenium/webdriver/safari/launcher_tests.py [55-59]

    -@pytest.mark.skip(reason="Need to be updated")
    -def test_launch_safari_with_legacy_flag(mocker, driver_class):
    -    import subprocess
    +def test_launch_safari_with_updated_implementation(mocker, driver_class):
    +    # Update test logic here to reflect new Safari webdriver implementation
    +    pass
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: While updating the test case is a good suggestion, it requires additional context and implementation details to be actionable. The suggestion is valid but lacks specific guidance on how to update the test.

    5

    💡 Need additional feedback ? start a PR chat

    Copy link
    Contributor

    qodo-merge-pro bot commented Nov 1, 2024

    CI Failure Feedback 🧐

    Action: Python / Safari Tests / Integration Tests (safari)

    Failed stage: Run Bazel [❌]

    Failed test name: test_launch

    Failure summary:

    The action failed because the test test_launch in the file launcher_tests.py encountered an error:

  • The safaridriver service unexpectedly exited with a status code of 1, causing a WebDriverException.
  • This error occurred during the setup of the test_launch test case.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  macOS
    ...
    
    368:  Received 46137344 of 117583330 (39.2%), 43.8 MBs/sec
    369:  Cache Size: ~112 MB (117583330 B)
    370:  [command]/usr/local/bin/gtar -xf /Users/runner/work/_temp/3aba0281-5c30-41fc-b24a-e3d43a60429c/cache.tzst -P -C /Users/runner/work/selenium/selenium --delay-directory-restore --use-compress-program unzstd
    371:  Received 117583330 of 117583330 (100.0%), 55.9 MBs/sec
    372:  Cache restored successfully
    373:  Successfully restored cache from setup-bazel-2-darwin-bazelisk-4ef214f6d8a6e28ff412dd44d226afc3b6334b9c20eeb496c07845198f61b42f
    374:  ##[endgroup]
    375:  ##[group]Restore cache for disk-py-safari
    376:  Failed to restore disk-py-safari cache
    ...
    
    385:  Received 882202215 of 890590823 (99.1%), 119.8 MBs/sec
    386:  Cache Size: ~849 MB (890590823 B)
    387:  [command]/usr/local/bin/gtar -xf /Users/runner/work/_temp/0349b977-d8b1-4759-bb70-1700eae31d0a/cache.tzst -P -C /Users/runner/work/selenium/selenium --delay-directory-restore --use-compress-program unzstd
    388:  Received 890590823 of 890590823 (100.0%), 105.8 MBs/sec
    389:  Cache restored successfully
    390:  Successfully restored cache from setup-bazel-2-darwin-repository-116ac5b99cf3b70eccd2c159c2466da5a1a79aae8e86829a1d6f64fbc80014a8
    391:  ##[endgroup]
    392:  ##[group]Restore cache for external-py-safari-manifest
    393:  Failed to restore external-py-safari-manifest cache
    ...
    
    623:  �[32m[930 / 1,803]�[0m Compiling src/google/protobuf/descriptor.cc [for tool]; 11s darwin-sandbox, disk-cache ... (4 actions, 3 running)
    624:  �[32m[933 / 1,803]�[0m Compiling src/google/protobuf/descriptor.cc [for tool]; 13s darwin-sandbox, disk-cache ... (4 actions running)
    625:  �[32m[937 / 1,803]�[0m Compiling src/google/protobuf/descriptor.cc [for tool]; 14s darwin-sandbox, disk-cache ... (5 actions, 4 running)
    626:  �[32m[938 / 1,803]�[0m Compiling src/google/protobuf/descriptor.cc [for tool]; 16s darwin-sandbox, disk-cache ... (4 actions, 3 running)
    627:  �[32m[939 / 1,803]�[0m Compiling src/google/protobuf/descriptor.cc [for tool]; 17s darwin-sandbox, disk-cache ... (4 actions running)
    628:  �[32m[942 / 1,803]�[0m Compiling src/google/protobuf/compiler/ruby/ruby_generator.cc [for tool]; 2s darwin-sandbox, disk-cache ... (4 actions running)
    629:  �[32m[943 / 1,803]�[0m Compiling src/google/protobuf/compiler/python/pyi_generator.cc [for tool]; 2s darwin-sandbox, disk-cache ... (4 actions, 3 running)
    630:  �[32mINFO: �[0mFrom Linking external/protobuf~/libprotobuf.a [for tool]:
    631:  /Applications/Xcode_15.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: bazel-out/darwin_x86_64-opt-exec-ST-d57f47055a04/bin/external/protobuf~/_objs/protobuf/error_listener.o has no symbols
    ...
    
    743:  �[32m[1,803 / 1,804]�[0m Testing //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py; 3s local, disk-cache
    744:  �[31m�[1mFAIL: �[0m//py:test-safari-test/selenium/webdriver/safari/launcher_tests.py (see /Users/runner/.bazel/execroot/_main/bazel-out/darwin_x86_64-fastbuild/testlogs/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py/test_attempts/attempt_1.log)
    745:  �[32m[1,803 / 1,804]�[0m Testing //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py; 5s local, disk-cache
    746:  �[32m[1,803 / 1,804]�[0m Testing //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py; 6s local, disk-cache
    747:  �[31m�[1mFAIL: �[0m//py:test-safari-test/selenium/webdriver/safari/launcher_tests.py (see /Users/runner/.bazel/execroot/_main/bazel-out/darwin_x86_64-fastbuild/testlogs/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py/test_attempts/attempt_2.log)
    748:  �[32m[1,803 / 1,804]�[0m Testing //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py; 8s local, disk-cache
    749:  �[31m�[1mFAIL: �[0m//py:test-safari-test/selenium/webdriver/safari/launcher_tests.py (see /Users/runner/.bazel/execroot/_main/bazel-out/darwin_x86_64-fastbuild/testlogs/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py/test.log)
    750:  ==================== Test output for //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py:
    751:  �[31m�[1mFAILED: �[0m//py:test-safari-test/selenium/webdriver/safari/launcher_tests.py (Summary)
    752:  ============================= test session starts ==============================
    753:  platform darwin -- Python 3.8.19, pytest-7.4.4, pluggy-1.3.0
    754:  rootdir: /Users/runner/.bazel/execroot/_main/bazel-out/darwin_x86_64-fastbuild/bin/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py.runfiles/_main/py
    755:  configfile: pyproject.toml
    756:  plugins: instafail-0.5.0, trio-0.8.0, mock-3.12.0
    757:  collected 5 items
    758:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch ERROR   [ 20%]
    759:  ________________________ ERROR at setup of test_launch _________________________
    ...
    
    783:  py/selenium/webdriver/common/service.py:121: WebDriverException
    784:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch_with_invalid_executable_path_raises_exception PASSED [ 40%]
    785:  py/test/selenium/webdriver/safari/launcher_tests.py::TestTechnologyPreview::test_launch SKIPPED [ 60%]
    786:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch_safari_with_legacy_flag SKIPPED [ 80%]
    787:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch_safari_without_legacy_flag PASSED [100%]
    788:  =========================== short test summary info ============================
    789:  SKIPPED [1] py/test/selenium/webdriver/safari/launcher_tests.py:51: Preview not installed
    790:  SKIPPED [1] py/test/selenium/webdriver/safari/launcher_tests.py:55: Need to be updated
    791:  ERROR py/test/selenium/webdriver/safari/launcher_tests.py::test_launch - selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/safaridriver unexpectedly exited. Status code was: 1
    792:  ==================== 2 passed, 2 skipped, 1 error in 0.78s =====================
    793:  ================================================================================
    794:  ==================== Test output for //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py:
    795:  ============================= test session starts ==============================
    796:  platform darwin -- Python 3.8.19, pytest-7.4.4, pluggy-1.3.0
    797:  rootdir: /Users/runner/.bazel/execroot/_main/bazel-out/darwin_x86_64-fastbuild/bin/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py.runfiles/_main/py
    798:  configfile: pyproject.toml
    799:  plugins: instafail-0.5.0, trio-0.8.0, mock-3.12.0
    800:  collected 5 items
    801:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch ERROR   [ 20%]
    802:  ________________________ ERROR at setup of test_launch _________________________
    ...
    
    822:  py/selenium/webdriver/common/service.py:121: WebDriverException
    823:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch_with_invalid_executable_path_raises_exception PASSED [ 40%]
    824:  py/test/selenium/webdriver/safari/launcher_tests.py::TestTechnologyPreview::test_launch SKIPPED [ 60%]
    825:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch_safari_with_legacy_flag SKIPPED [ 80%]
    826:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch_safari_without_legacy_flag PASSED [100%]
    827:  =========================== short test summary info ============================
    828:  SKIPPED [1] py/test/selenium/webdriver/safari/launcher_tests.py:51: Preview not installed
    829:  SKIPPED [1] py/test/selenium/webdriver/safari/launcher_tests.py:55: Need to be updated
    830:  ERROR py/test/selenium/webdriver/safari/launcher_tests.py::test_launch - selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/safaridriver unexpectedly exited. Status code was: 1
    831:  ==================== 2 passed, 2 skipped, 1 error in 0.87s =====================
    832:  ================================================================================
    833:  ==================== Test output for //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py:
    834:  ============================= test session starts ==============================
    835:  platform darwin -- Python 3.8.19, pytest-7.4.4, pluggy-1.3.0
    836:  rootdir: /Users/runner/.bazel/execroot/_main/bazel-out/darwin_x86_64-fastbuild/bin/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py.runfiles/_main/py
    837:  configfile: pyproject.toml
    838:  plugins: instafail-0.5.0, trio-0.8.0, mock-3.12.0
    839:  collected 5 items
    840:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch ERROR   [ 20%]
    841:  ________________________ ERROR at setup of test_launch _________________________
    ...
    
    861:  py/selenium/webdriver/common/service.py:121: WebDriverException
    862:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch_with_invalid_executable_path_raises_exception PASSED [ 40%]
    863:  py/test/selenium/webdriver/safari/launcher_tests.py::TestTechnologyPreview::test_launch SKIPPED [ 60%]
    864:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch_safari_with_legacy_flag SKIPPED [ 80%]
    865:  py/test/selenium/webdriver/safari/launcher_tests.py::test_launch_safari_without_legacy_flag PASSED [100%]
    866:  =========================== short test summary info ============================
    867:  SKIPPED [1] py/test/selenium/webdriver/safari/launcher_tests.py:51: Preview not installed
    868:  SKIPPED [1] py/test/selenium/webdriver/safari/launcher_tests.py:55: Need to be updated
    869:  ERROR py/test/selenium/webdriver/safari/launcher_tests.py::test_launch - selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/safaridriver unexpectedly exited. Status code was: 1
    870:  ==================== 2 passed, 2 skipped, 1 error in 0.72s =====================
    871:  ================================================================================
    872:  �[32mINFO: �[0mFound 1 test target...
    873:  Target //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py up-to-date:
    874:  bazel-bin/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py-runner.py
    875:  bazel-bin/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py
    876:  �[32mINFO: �[0mElapsed time: 319.085s, Critical Path: 82.76s
    877:  �[32mINFO: �[0m1804 processes: 2 disk cache hit, 786 internal, 253 darwin-sandbox, 4 local, 759 worker.
    878:  �[32mINFO: �[0mBuild completed, 1 test FAILED, 1804 total actions
    879:  //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py        �[0m�[31m�[1mFAILED�[0m in 3 out of 3 in 2.7s
    880:  Stats over 3 runs: max = 2.7s, min = 2.2s, avg = 2.5s, dev = 0.2s
    881:  /Users/runner/.bazel/execroot/_main/bazel-out/darwin_x86_64-fastbuild/testlogs/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py/test.log
    882:  /Users/runner/.bazel/execroot/_main/bazel-out/darwin_x86_64-fastbuild/testlogs/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py/test_attempts/attempt_1.log
    883:  /Users/runner/.bazel/execroot/_main/bazel-out/darwin_x86_64-fastbuild/testlogs/py/test-safari-test/selenium/webdriver/safari/launcher_tests.py/test_attempts/attempt_2.log
    884:  Executed 1 out of 1 test: �[0m�[31m�[1m1 fails locally�[0m.
    885:  �[0m
    886:  ##[error]Process completed with exit code 3.
    

    ✨ 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 7c389f9 into trunk Nov 1, 2024
    14 checks passed
    @VietND96 VietND96 deleted the safari-driver branch November 1, 2024 02:54
    @VietND96 VietND96 mentioned this pull request Nov 4, 2024
    8 tasks
    @cclauss
    Copy link
    Contributor

    cclauss commented Nov 7, 2024

    Has this fix landed in any release? https://github.com/SeleniumHQ/selenium/releases

    @VietND96
    Copy link
    Member Author

    VietND96 commented Nov 7, 2024

    FYI, Chrome early stable release will comes out, we also will do a minor release next week including this fix. https://chromiumdash.appspot.com/schedule
    cc @diemol

    @rsugumar
    Copy link

    rsugumar commented Nov 7, 2024

    waiting for this fix to come out soon. I see this error in py 3.12.7 / 3.13. Let me check quickly in 3.11

    @VietND96
    Copy link
    Member Author

    VietND96 commented Nov 7, 2024

    I think Python version is not a problem, you can try to pin selenium==4.25.0 in the meantime.

    @cclauss
    Copy link
    Contributor

    cclauss commented Nov 10, 2024

    Pinning to selenium==4.25.0 does work. Thanks. Would it be possible to get these fixes into a Nightly build?

    @diemol
    Copy link
    Member

    diemol commented Nov 10, 2024

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    4 participants