diff --git a/src/Api/Concerns/InteractsWithElements.php b/src/Api/Concerns/InteractsWithElements.php index 7bec5196..2f2a3002 100644 --- a/src/Api/Concerns/InteractsWithElements.php +++ b/src/Api/Concerns/InteractsWithElements.php @@ -23,6 +23,18 @@ public function click(string $text, array $options = []): Webpage return $this; } + /** + * Double click the link with the given text. + * + * @param array $options + */ + public function doubleClick(string $text, array $options = []): Webpage + { + $this->guessLocator($text)->dblclick($options); + + return $this; + } + /** * Get the text of the element matching the given selector. */ diff --git a/tests/Browser/Webpage/ClickTest.php b/tests/Browser/Webpage/ClickTest.php index 7ff3e58c..c4ec257f 100644 --- a/tests/Browser/Webpage/ClickTest.php +++ b/tests/Browser/Webpage/ClickTest.php @@ -93,3 +93,69 @@ $page->click('#button', options: ['clickCount' => 2]); $page->assertSeeIn('#result', 'Option-2 clicked'); }); + +it('can double click an element', function (): void { + Route::get('/', fn (): string => ' +

+ '); + + $page = visit('/'); + + $page->doubleClick('#button'); + $page->assertSeeIn('#result', 'Double Clicked'); +}); + +it('can double click an element with text selector', function (): void { + Route::get('/', fn (): string => ' +

+
+ Double Click Me +
'); + + $page = visit('/'); + + $page->doubleClick('Double Click Me'); + $page->assertSeeIn('#result', 'Double Clicked'); +}); + +it('can double click on different element types', function (string $element): void { + Route::get('/', fn (): string => " +

+ $element + "); + + $page = visit('/'); + + $page->doubleClick('#clickable'); + $page->assertSeeIn('#result', 'Double Clicked'); +})->with([ + '', + '
Button
', + '', + '', + '', + '', + '', + 'Button', +]); + +it('can double click to select text content', function (): void { + Route::get('/', fn (): string => ' +

+ This is some selectable text content that can be selected +

+

+ '); + + $page = visit('/'); + + $page->doubleClick('#selectable'); + $page->assertSeeIn('#result', 'selected'); +});