Skip to content

Commit e94e33a

Browse files
authored
[1.6] Fix scroll with values higher than possible (#419)
1 parent 9f36afb commit e94e33a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Input/Mouse.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,11 @@ private function scroll(int $distanceY, int $distanceX = 0): self
183183
$scrollableArea = $this->page->getLayoutMetrics()->getCssContentSize();
184184
$visibleArea = $this->page->getLayoutMetrics()->getCssVisualViewport();
185185

186-
$distanceX = $this->getMaximumDistance($distanceX, $visibleArea['pageX'], $scrollableArea['width']);
187-
$distanceY = $this->getMaximumDistance($distanceY, $visibleArea['pageY'], $scrollableArea['height']);
186+
$maximumX = $scrollableArea['width'] - $visibleArea['clientWidth'];
187+
$maximumY = $scrollableArea['height'] - $visibleArea['clientHeight'];
188+
189+
$distanceX = $this->getMaximumDistance($distanceX, $visibleArea['pageX'], $maximumX);
190+
$distanceY = $this->getMaximumDistance($distanceY, $visibleArea['pageY'], $maximumY);
188191

189192
$targetX = $visibleArea['pageX'] + $distanceX;
190193
$targetY = $visibleArea['pageY'] + $distanceY;
@@ -328,7 +331,7 @@ public function findElement(Selector $selector, int $position = 1): self
328331
*
329332
* @param int $distance Distance to scroll, positive or negative
330333
* @param int $current Current position
331-
* @param int $maximum Maximum posible distance
334+
* @param int $maximum Maximum possible distance
332335
*
333336
* @return int allowed distance to scroll
334337
*/

tests/MouseApiTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,23 @@ public function testScroll(): void
8585
$windowScrollY = $page->evaluate('window.scrollY')->getReturnValue();
8686

8787
$this->assertEquals(100, $windowScrollY);
88+
$this->assertEquals(100, $page->mouse()->getPosition()['y']);
8889

8990
// scrolling 100px up should revert the last action
9091
$page->mouse()->scrollUp(100);
9192

9293
$windowScrollY = $page->evaluate('window.scrollY')->getReturnValue();
9394

9495
$this->assertEquals(0, $windowScrollY);
96+
$this->assertEquals(0, $page->mouse()->getPosition()['y']);
97+
98+
// try to scroll more than possible
99+
$page->mouse()->scrollDown(10000);
100+
101+
$windowScrollY = $page->evaluate('window.scrollY')->getReturnValue();
102+
103+
$this->assertLessThan(10000, $windowScrollY);
104+
$this->assertLessThan(10000, $page->mouse()->getPosition()['y']);
95105
}
96106

97107
/**

0 commit comments

Comments
 (0)