Skip to content

fix: humanize not being provided on mouse.click actions inside WebElement#393

Open
tiagogcampos wants to merge 4 commits intoautoscrape-labs:mainfrom
tiagogcampos:fix/humanize
Open

fix: humanize not being provided on mouse.click actions inside WebElement#393
tiagogcampos wants to merge 4 commits intoautoscrape-labs:mainfrom
tiagogcampos:fix/humanize

Conversation

@tiagogcampos
Copy link
Copy Markdown

@tiagogcampos tiagogcampos commented Apr 6, 2026

Pull Request

Description

Provides humanize boolean to mouse.click actions performed on WebElement.

Related Issue(s)

Fixes #392

Type of Change

  • 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 not work as expected)
  • Documentation update
  • Refactoring (no functional changes, no API changes)
  • Performance improvement
  • Tests (adding missing tests or correcting existing tests)
  • Build or CI/CD related changes

How Has This Been Tested?

Tested by executing the test suite.

Testing Checklist

  • Unit tests added/updated
  • Integration tests added/updated
  • All existing tests pass

Screenshots

Implementation Details

API Changes

Additional Info

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have run poetry run task lint and fixed any issues
  • I have run poetry run task test and all tests pass
  • My commits follow the conventional commits style

Summary by CodeRabbit

  • Bug Fixes

    • Humanized click now properly applies the humanize setting to mouse interactions.
  • Tests

    • Improved async generator cleanup in connection handler tests.
    • Enhanced humanized click test assertions to verify correct parameter handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

📝 Walkthrough

Walkthrough

The pull request fixes a bug where the humanize=True flag in WebElement.click() was not propagated to the underlying Mouse.click() invocation. It also refactors test fixtures to remove the pytest_asyncio dependency and improves async generator cleanup in tests.

Changes

Cohort / File(s) Summary
Main Code Bug Fix
pydoll/elements/web_element.py
Added humanize=True keyword argument to self._mouse.click() call in the humanized click path to ensure the humanize flag is properly forwarded.
Test Async Cleanup
tests/test_connection_handler.py
Wrapped async generator advancement in try/finally block with explicit aclose() call to ensure proper resource cleanup.
Test Fixture & Assertion Updates
tests/test_web_element.py
Converted mock_connection_handler fixtures from async to synchronous; updated humanized click test assertions to pass humanize as explicit parameter and keyword argument in mock expectations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A whisker-twitch of joy, I hop with glee,
The humanize flag now flows wild and free!
Where Mouse met Click without a caring thought,
Now harmony and consistency are sought.
Tests are cleaner, fixtures lean and bright,
The rabbit's work shines clear—all working right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description adequately covers the main purpose, related issue (#392), type of change (bug fix and refactoring), testing checklist, and pre-review checklist with most items completed.
Linked Issues check ✅ Passed The code changes successfully forward the humanize flag to Mouse.click in the humanized branch, exactly as required by issue #392, and tests are updated to verify this behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #392: WebElement.click now forwards humanize=True to Mouse.click, and tests are updated to support and verify this behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately identifies the main change: forwarding the humanize flag to Mouse.click in WebElement.click, which directly addresses the bug described in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tiagogcampos tiagogcampos changed the title Fix/humanize fix: humanize not being provided on mouse.click actions inside WebElement Apr 6, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/test_web_element.py (1)

2031-2032: Avoid redefining mock_connection_handler in the same module.

The second fixture definition overrides the first one, which can silently change setup behavior for unrelated tests and makes fixture resolution harder to reason about.

♻️ Proposed refactor
-@pytest.fixture
-def mock_connection_handler():
+@pytest.fixture
+def iframe_mock_connection_handler():
     """Mock connection handler for WebElement tests."""
     with patch('pydoll.connection.ConnectionHandler', autospec=True) as mock:
         handler = mock.return_value
         handler.execute_command = AsyncMock()
         handler._connection_port = 9222
         yield handler

-@pytest.fixture
-def iframe_element(mock_connection_handler):
+@pytest.fixture
+def iframe_element(iframe_mock_connection_handler):
     """Iframe element fixture for iframe-related tests."""
     attributes_list = ['id', 'test-iframe', 'tag_name', 'iframe']
     return WebElement(
         object_id='iframe-object-id',
-        connection_handler=mock_connection_handler,
+        connection_handler=iframe_mock_connection_handler,
         method='css',
         selector='iframe#test-iframe',
         attributes_list=attributes_list,
     )

-@pytest.fixture
-def element_in_iframe(mock_connection_handler):
+@pytest.fixture
+def element_in_iframe(iframe_mock_connection_handler):
     """Element inside an iframe (has _iframe_context set)."""
     attributes_list = ['id', 'button-in-iframe', 'tag_name', 'button']
     element = WebElement(
         object_id='button-object-id',
-        connection_handler=mock_connection_handler,
+        connection_handler=iframe_mock_connection_handler,
         method='css',
         selector='button',
         attributes_list=attributes_list,
     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_web_element.py` around lines 2031 - 2032, There are two fixtures
both named mock_connection_handler which causes the latter to override the
former; locate the duplicate fixture definitions of mock_connection_handler and
either remove/merge the redundant one or rename the second fixture to a unique
name (e.g., mock_connection_handler_alt) and update all tests that rely on the
second fixture to use the new name; ensure the intended setup logic from both
definitions is preserved by consolidating shared behavior into a single fixture
function (or using helper functions) and update any imports/usages accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/test_web_element.py`:
- Around line 2031-2032: There are two fixtures both named
mock_connection_handler which causes the latter to override the former; locate
the duplicate fixture definitions of mock_connection_handler and either
remove/merge the redundant one or rename the second fixture to a unique name
(e.g., mock_connection_handler_alt) and update all tests that rely on the second
fixture to use the new name; ensure the intended setup logic from both
definitions is preserved by consolidating shared behavior into a single fixture
function (or using helper functions) and update any imports/usages accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c6f7e33f-e7cd-469a-b909-ee18563807a2

📥 Commits

Reviewing files that changed from the base of the PR and between 07f4d9a and 368cd18.

📒 Files selected for processing (3)
  • pydoll/elements/web_element.py
  • tests/test_connection_handler.py
  • tests/test_web_element.py

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebElement click(humanize=True) does not forward humanize flag to Mouse.click

1 participant