diff --git a/src/Input/Mouse.php b/src/Input/Mouse.php index 5aae49f..923393e 100644 --- a/src/Input/Mouse.php +++ b/src/Input/Mouse.php @@ -31,8 +31,8 @@ class Mouse */ protected $page; - protected $x = 0; - protected $y = 0; + protected $x = 0.0; + protected $y = 0.0; protected $button = self::BUTTON_NONE; @@ -45,8 +45,8 @@ public function __construct(Page $page) } /** - * @param int $x - * @param int $y + * @param float $x + * @param float $y * @param array|null $options * * @throws \HeadlessChromium\Exception\CommunicationException @@ -54,7 +54,7 @@ public function __construct(Page $page) * * @return $this */ - public function move(int $x, int $y, ?array $options = null) + public function move(float $x, float $y, ?array $options = null) { $this->page->assertNotClosed(); @@ -329,13 +329,13 @@ public function findElement(Selector $selector, int $position = 1): self /** * Get the maximum distance to scroll a page. * - * @param int $distance Distance to scroll, positive or negative - * @param int $current Current position - * @param int $maximum Maximum possible distance + * @param float $distance Distance to scroll, positive or negative + * @param float $current Current position + * @param float $maximum Maximum possible distance * - * @return int allowed distance to scroll + * @return float allowed distance to scroll */ - private function getMaximumDistance(int $distance, int $current, int $maximum): int + private function getMaximumDistance(float $distance, float $current, float $maximum): float { $result = $current + $distance; diff --git a/tests/MouseApiTest.php b/tests/MouseApiTest.php index 5413a7b..113d053 100644 --- a/tests/MouseApiTest.php +++ b/tests/MouseApiTest.php @@ -82,7 +82,7 @@ public function testScroll(): void $windowScrollY = $page->evaluate('window.scrollY')->getReturnValue(); self::assertSame(100, $windowScrollY); - self::assertSame(100, $page->mouse()->getPosition()['y']); + self::assertSame(100.0, $page->mouse()->getPosition()['y']); // scrolling 100px up should revert the last action $page->mouse()->scrollUp(100); @@ -90,7 +90,7 @@ public function testScroll(): void $windowScrollY = $page->evaluate('window.scrollY')->getReturnValue(); self::assertSame(0, $windowScrollY); - self::assertSame(0, $page->mouse()->getPosition()['y']); + self::assertSame(0.0, $page->mouse()->getPosition()['y']); // try to scroll more than possible $page->mouse()->scrollDown(10000); @@ -98,7 +98,7 @@ public function testScroll(): void $windowScrollY = $page->evaluate('window.scrollY')->getReturnValue(); self::assertLessThan(10000, $windowScrollY); - self::assertLessThan(10000, $page->mouse()->getPosition()['y']); + self::assertLessThan(10000.0, $page->mouse()->getPosition()['y']); } /** @@ -265,10 +265,10 @@ public function testGetPosition(): void $x = $page->mouse()->getPosition()['x']; $y = $page->mouse()->getPosition()['y']; - self::assertGreaterThanOrEqual(1, $x); // 8 - self::assertLessThanOrEqual(51, $x); + self::assertGreaterThanOrEqual(1.0, $x); // 8 + self::assertLessThanOrEqual(51.0, $x); - self::assertGreaterThanOrEqual(1, $y); // 87 - self::assertLessThanOrEqual(107, $y); + self::assertGreaterThanOrEqual(1.0, $y); // 87 + self::assertLessThanOrEqual(107.0, $y); } }