diff --git a/pydoll/elements/web_element.py b/pydoll/elements/web_element.py index 716644e0..39704494 100644 --- a/pydoll/elements/web_element.py +++ b/pydoll/elements/web_element.py @@ -605,7 +605,7 @@ async def click( logger.info( f'Clicking element (humanized): x={position_to_click[0]}, y={position_to_click[1]}' ) - await self._mouse.click(position_to_click[0], position_to_click[1]) + await self._mouse.click(position_to_click[0], position_to_click[1], humanize=True) return logger.info( diff --git a/tests/test_connection_handler.py b/tests/test_connection_handler.py index a90c64af..4bb22e1a 100644 --- a/tests/test_connection_handler.py +++ b/tests/test_connection_handler.py @@ -215,8 +215,13 @@ async def test__incoming_messages(connection_handler): connection_handler._ws_connection.recv = AsyncMock( return_value='{"id": 1, "method": "SomeMethod"}' ) - async_generator = connection_handler._incoming_messages() - result = await anext(async_generator) + + try: + async_generator = connection_handler._incoming_messages() + result = await anext(async_generator) + finally: + await async_generator.aclose() + assert result == '{"id": 1, "method": "SomeMethod"}' diff --git a/tests/test_web_element.py b/tests/test_web_element.py index d8412edf..e42da73d 100644 --- a/tests/test_web_element.py +++ b/tests/test_web_element.py @@ -4,7 +4,6 @@ from unittest.mock import AsyncMock, patch import pytest -import pytest_asyncio from pydoll.browser.options import ChromiumOptions as Options from pydoll.browser.chromium.chrome import Chrome @@ -22,8 +21,8 @@ from pydoll.protocol.runtime.types import CallArgument -@pytest_asyncio.fixture -async def mock_connection_handler(): +@pytest.fixture +def mock_connection_handler(): """Mock connection handler for WebElement tests.""" with patch('pydoll.connection.ConnectionHandler', autospec=True) as mock: handler = mock.return_value @@ -846,9 +845,10 @@ async def test_click_humanized_uses_mouse(self, element_with_mouse, mouse_mock): 'result': {'model': {'content': bounds}} } - await element_with_mouse.click(humanize=True) + humanize = True + await element_with_mouse.click(humanize=humanize) - mouse_mock.click.assert_called_once_with(50.0, 50.0) + mouse_mock.click.assert_called_once_with(50.0, 50.0, humanize=humanize) @pytest.mark.asyncio async def test_click_humanized_with_offset(self, element_with_mouse, mouse_mock): @@ -860,9 +860,10 @@ async def test_click_humanized_with_offset(self, element_with_mouse, mouse_mock) 'result': {'model': {'content': bounds}} } - await element_with_mouse.click(x_offset=10, y_offset=20, humanize=True) + humanize = True + await element_with_mouse.click(x_offset=10, y_offset=20, humanize=humanize) - mouse_mock.click.assert_called_once_with(60.0, 70.0) + mouse_mock.click.assert_called_once_with(60.0, 70.0, humanize=humanize) @pytest.mark.asyncio async def test_click_humanize_false_uses_raw_cdp(self, element_with_mouse, mouse_mock): @@ -2019,7 +2020,6 @@ async def test_get_siblings_elements_element_not_found_exception(self): """ import pytest -import pytest_asyncio from unittest.mock import AsyncMock, patch from pydoll.elements.web_element import WebElement @@ -2028,8 +2028,8 @@ async def test_get_siblings_elements_element_not_found_exception(self): from pydoll.exceptions import InvalidIFrame -@pytest_asyncio.fixture -async def mock_connection_handler(): +@pytest.fixture +def mock_connection_handler(): """Mock connection handler for WebElement tests.""" with patch('pydoll.connection.ConnectionHandler', autospec=True) as mock: handler = mock.return_value