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 WebKitGTK driver name check #15046

Merged

Conversation

lauromoura
Copy link
Contributor

@lauromoura lauromoura commented Jan 8, 2025

User description

Description

Similar to WPEWebKit changes from 24d88d7, WebKitGTK does not follow the simple capitalization scheme for the driver name.

This commit also changes the default WebKitWebDriver binary to the first one in PATH through shutil.which, instead of just the binary name.

(Note: The effort to move to pathlib instead of shutil[1] is more related to shutil's functions that work on files and directories, like copy and move, instead of which, which just searches the executable paths for the given command.)

[1] https://discuss.python.org/t/incrementally-move-high-level-path-operations-from-shutil-to-pathlib/19208

Motivation and Context

Without this fix, using the helper WebKitGTK driver class fails unconditionally. This affects running Selenium's own tests with WebkitGTK, for example (which we import into WebKit, alongside WPT's WebDriver tests).

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


Description

  • Fixed WebKitGTK driver name capitalization check in conftest.py.

  • Updated WebKitWebDriver binary to use shutil.which for path resolution.

  • Ensured compatibility with WebKitGTK driver class for Selenium tests.


Changes walkthrough 📝

Relevant files
Bug fix
conftest.py
Fix WebKitGTK driver name capitalization check                     

py/conftest.py

  • Adjusted WebKitGTK driver name check to be case-insensitive.
  • Ensured driver class is correctly set to WebKitGTK.
  • +2/-1     
    service.py
    Update WebKitWebDriver binary resolution using `shutil.which`

    py/selenium/webdriver/webkitgtk/service.py

  • Changed DEFAULT_EXECUTABLE_PATH to use shutil.which.
  • Updated docstring to reflect the new binary resolution method.
  • +3/-2     

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

    Copy link
    Contributor

    qodo-merge-pro bot commented Jan 8, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Documentation Mismatch

    The class docstring still refers to 'WPEWebDriver' instead of 'WebKitWebDriver' which may be confusing for users

    """A Service class that is responsible for the starting and stopping of
    `WPEWebDriver`.
    Error Handling

    No error handling if shutil.which() returns None when WebKitWebDriver is not found in PATH

    DEFAULT_EXECUTABLE_PATH: str = shutil.which("WebKitWebDriver")

    Copy link
    Contributor

    qodo-merge-pro bot commented Jan 8, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add proper error handling when the required executable is not found in system PATH

    Add error handling for when shutil.which() returns None to provide a clear error
    message when WebKitWebDriver is not found in PATH.

    py/selenium/webdriver/webkitgtk/service.py [25]

    -DEFAULT_EXECUTABLE_PATH: str = shutil.which("WebKitWebDriver")
    +_driver_path = shutil.which("WebKitWebDriver")
    +if _driver_path is None:
    +    raise FileNotFoundError("WebKitWebDriver not found in PATH")
    +DEFAULT_EXECUTABLE_PATH: str = _driver_path
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: This is a valuable suggestion that adds robust error handling for a critical initialization step. Early failure with a clear error message when the required executable is missing would improve user experience significantly.

    8
    General
    Fix incorrect driver name in documentation to prevent user confusion

    The docstring incorrectly mentions WPEWebDriver instead of WebKitWebDriver, which
    could mislead users. Update the docstring to reference the correct driver name.

    py/selenium/webdriver/webkitgtk/service.py [29-30]

     """A Service class that is responsible for the starting and stopping of
    -`WPEWebDriver`."""
    +`WebKitWebDriver`."""
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion correctly identifies a documentation inconsistency that could confuse users. Having accurate documentation is important for maintainability and user guidance.

    7

    Similar to WPEWebKit changes from 24d88d7, WebKitGTK does not
    follow the simple capitalization scheme for the driver name.
    
    This commit also changes the default `WebKitWebDriver` binary to the
    first one in `PATH` through shutil.which, instead of just the binary
    name.
    
    (Note: The effort to move to `pathlib` instead of `shutil`[1] is more
    related to shutil's functions that work on files and directories, like
    copy and move, instead of `which`, which just searches the executable
    paths for the given command.)
    
    [1] https://discuss.python.org/t/incrementally-move-high-level-path-operations-from-shutil-to-pathlib/19208
    @lauromoura lauromoura force-pushed the webkitgtk-fix-driver-class-check branch from 8710c35 to 2d59089 Compare January 8, 2025 01:24
    @lauromoura
    Copy link
    Contributor Author

    Updated addressing the docstring mishap.

    About the shutil.which() return, it'll be handled by service.Service.start(), as, IIUC, it allows the user creating an instance with an empty path, setting it later.

    @VietND96 VietND96 changed the title py: Fix WebKitGTK driver name check [py] Fix WebKitGTK driver name check Jan 8, 2025
    @VietND96 VietND96 added the C-py label Jan 8, 2025
    Copy link
    Member

    @diemol diemol 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, @lauromoura!

    @diemol diemol merged commit 7425162 into SeleniumHQ:trunk Jan 8, 2025
    17 checks passed
    yvsvarma pushed a commit to yvsvarma/selenium that referenced this pull request Jan 9, 2025
    py: Fix WebKitGTK driver name.
    
    Similar to WPEWebKit changes from 24d88d7, WebKitGTK does not
    follow the simple capitalization scheme for the driver name.
    
    This commit also changes the default `WebKitWebDriver` binary to the
    first one in `PATH` through shutil.which, instead of just the binary
    name.
    
    (Note: The effort to move to `pathlib` instead of `shutil`[1] is more
    related to shutil's functions that work on files and directories, like
    copy and move, instead of `which`, which just searches the executable
    paths for the given command.)
    
    [1] https://discuss.python.org/t/incrementally-move-high-level-path-operations-from-shutil-to-pathlib/19208
    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.

    3 participants