@@ -954,13 +954,12 @@ class TestPerformScrollLoop:
954954 async def test_perform_scroll_loop_dispatches_events (self , mock_tab ):
955955 """Test scroll loop dispatches mouse wheel events."""
956956 from pydoll .interactions .scroll import Scroll , ScrollTimingConfig
957- from unittest .mock import patch , AsyncMock
957+ from unittest .mock import patch , AsyncMock , MagicMock
958958
959959 mock_tab ._execute_command .return_value = {
960960 'result' : {'result' : {'value' : '[400, 300]' }}
961961 }
962962
963- # Very short duration for fast test
964963 config = ScrollTimingConfig (
965964 min_duration = 0.01 ,
966965 max_duration = 0.02 ,
@@ -969,13 +968,19 @@ async def test_perform_scroll_loop_dispatches_events(self, mock_tab):
969968 )
970969 scroll = Scroll (mock_tab , timing = config )
971970
972- with patch ('asyncio.sleep' , new_callable = AsyncMock ):
973- scrolled = await scroll ._perform_scroll_loop (
974- effective_distance = 100.0 ,
975- duration = 0.01 ,
976- is_vertical = True ,
977- direction = 1 ,
978- )
971+ # Mock time to advance in steps
972+ # Start at 0, then 0.005 (halfway), then 0.02 (end)
973+ mock_loop = MagicMock ()
974+ mock_loop .time .side_effect = [0.0 , 0.005 , 0.02 ]
975+
976+ with patch ('asyncio.get_running_loop' , return_value = mock_loop ):
977+ with patch ('asyncio.sleep' , new_callable = AsyncMock ):
978+ scrolled = await scroll ._perform_scroll_loop (
979+ effective_distance = 100.0 ,
980+ duration = 0.01 ,
981+ is_vertical = True ,
982+ direction = 1 ,
983+ )
979984
980985 # Should have dispatched at least one event
981986 assert mock_tab ._execute_command .call_count >= 1
0 commit comments