@@ -633,19 +633,20 @@ async def test_calculate_duration(self, mock_tab):
633633 async def test_calculate_duration_increases_with_distance (self , mock_tab ):
634634 """Test that longer distances result in longer durations."""
635635 from pydoll .interactions .scroll import Scroll , ScrollTimingConfig
636+ from unittest .mock import patch
636637
637638 config = ScrollTimingConfig (min_duration = 0.5 , max_duration = 1.5 )
638639 scroll = Scroll (mock_tab , timing = config )
639640
640- # Run multiple times to account for randomness
641- short_durations = [scroll ._calculate_duration (100.0 ) for _ in range (10 )]
642- long_durations = [scroll ._calculate_duration (2000.0 ) for _ in range (10 )]
641+ # Patch random.uniform to return a constant base duration
642+ # This ensures we are testing only the distance scaling logic
643+ with patch ('random.uniform' , return_value = 1.0 ):
644+ short_duration = scroll ._calculate_duration (100.0 )
645+ long_duration = scroll ._calculate_duration (5000.0 )
643646
644- avg_short = sum (short_durations ) / len (short_durations )
645- avg_long = sum (long_durations ) / len (long_durations )
646-
647- # Average of long distances should be greater
648- assert avg_long > avg_short
647+ # With constant base duration, the formula ensures longer distance -> longer duration
648+ # Formula: base_duration * (1 + 0.2 * (distance / 1000))
649+ assert long_duration > short_duration
649650
650651 @pytest .mark .asyncio
651652 async def test_get_viewport_center (self , mock_tab ):
0 commit comments