diff --git a/src/Api/Concerns/InteractsWithElements.php b/src/Api/Concerns/InteractsWithElements.php index 24566e7e..1c8a1c32 100644 --- a/src/Api/Concerns/InteractsWithElements.php +++ b/src/Api/Concerns/InteractsWithElements.php @@ -13,10 +13,12 @@ trait InteractsWithElements { /** * Click the link with the given text. + * + * @param array|null $options */ - public function click(string $text): self + public function click(string $text, ?array $options = null): self { - $this->guessLocator($text)->click(); + $this->guessLocator($text)->click($options); return $this; } @@ -187,10 +189,12 @@ public function attach(string $field, string $path): self /** * Press the button with the given text or name. + * + * @param array|null $options */ - public function press(string $button): self + public function press(string $button, ?array $options = null): self { - return $this->click($button); + return $this->click($button, $options); } /** diff --git a/tests/Browser/Webpage/ClickTest.php b/tests/Browser/Webpage/ClickTest.php index 0396359e..cfb689e8 100644 --- a/tests/Browser/Webpage/ClickTest.php +++ b/tests/Browser/Webpage/ClickTest.php @@ -73,3 +73,19 @@ '[name$="test"]', 'button[name="test"]', ]); + +it('forwards options to the underlying click', function (): void { + Route::get('/', fn (): string => ' + +
+ '); + + $page = visit('/'); + + // A left click would never fire the contextmenu handler, so this proves the + // `button` option reaches the underlying Playwright locator. The motivating + // use case is passing `noWaitAfter` for clicks that trigger a navigation. + $page->click('Menu', ['button' => 'right']); + + expect($page->text('#result'))->toBe('Right Clicked'); +}); diff --git a/tests/Browser/Webpage/PressTest.php b/tests/Browser/Webpage/PressTest.php index 2fc8b448..7a046dc7 100644 --- a/tests/Browser/Webpage/PressTest.php +++ b/tests/Browser/Webpage/PressTest.php @@ -91,3 +91,16 @@ expect($page->text('#result'))->toBe('Input Button Pressed'); }); + +it('forwards options to the underlying press', function (): void { + Route::get('/', fn (): string => ' + +
+ '); + + $page = visit('/'); + + $page->press('Submit', ['button' => 'right']); + + expect($page->text('#result'))->toBe('Right Pressed'); +});