Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Api/Concerns/InteractsWithElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ trait InteractsWithElements
{
/**
* Click the link with the given text.
*
* @param array<string, mixed>|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;
}
Expand Down Expand Up @@ -187,10 +189,12 @@ public function attach(string $field, string $path): self

/**
* Press the button with the given text or name.
*
* @param array<string, mixed>|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);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/Browser/Webpage/ClickTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,19 @@
'[name$="test"]',
'button[name="test"]',
]);

it('forwards options to the underlying click', function (): void {
Route::get('/', fn (): string => '
<button oncontextmenu="event.preventDefault(); document.getElementById(\'result\').textContent = \'Right Clicked\'">Menu</button>
<div id="result"></div>
');

$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');
});
13 changes: 13 additions & 0 deletions tests/Browser/Webpage/PressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '
<button oncontextmenu="event.preventDefault(); document.getElementById(\'result\').textContent = \'Right Pressed\'">Submit</button>
<div id="result"></div>
');

$page = visit('/');

$page->press('Submit', ['button' => 'right']);

expect($page->text('#result'))->toBe('Right Pressed');
});