From 543f3923d48dfdf4eabb93546f35c9cbe072c791 Mon Sep 17 00:00:00 2001 From: dmitritarasov Date: Fri, 17 Apr 2026 16:31:11 +0300 Subject: [PATCH 1/3] feat: Added the ability to click on elements using the data-test selector. --- src/Api/Concerns/InteractsWithElements.php | 10 ++++++++++ tests/Browser/Webpage/ClickSelectorTest.php | 22 +++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/Browser/Webpage/ClickSelectorTest.php diff --git a/src/Api/Concerns/InteractsWithElements.php b/src/Api/Concerns/InteractsWithElements.php index 24566e7e..d6aab86f 100644 --- a/src/Api/Concerns/InteractsWithElements.php +++ b/src/Api/Concerns/InteractsWithElements.php @@ -21,6 +21,16 @@ public function click(string $text): self return $this; } + /** + * Click on the specified data-test selector. + */ + public function clickSelector(string $selector): self + { + $this->guessLocator($selector)->click(); + + return $this; + } + /** * Get the text of the element matching the given selector. */ diff --git a/tests/Browser/Webpage/ClickSelectorTest.php b/tests/Browser/Webpage/ClickSelectorTest.php new file mode 100644 index 00000000..c2fb9275 --- /dev/null +++ b/tests/Browser/Webpage/ClickSelectorTest.php @@ -0,0 +1,22 @@ + ' +
+
+ Click Me +
+
+
+ '); + + $page = visit('/'); + + $page->clickSelector('@test-selector'); + + expect($page->text('#result'))->toBe('Selector Clicked'); +}); From 9965c9c25a23ddf9439262aeeee74a9bb599001e Mon Sep 17 00:00:00 2001 From: dmitritarasov Date: Fri, 17 Apr 2026 18:51:05 +0300 Subject: [PATCH 2/3] fix: Replaced the duplicate method with an improved PHPDoc for click() instead --- src/Api/Concerns/InteractsWithElements.php | 14 ++----------- tests/Browser/Webpage/ClickSelectorTest.php | 22 --------------------- tests/Browser/Webpage/ClickTest.php | 17 ++++++++++++++++ 3 files changed, 19 insertions(+), 34 deletions(-) delete mode 100644 tests/Browser/Webpage/ClickSelectorTest.php diff --git a/src/Api/Concerns/InteractsWithElements.php b/src/Api/Concerns/InteractsWithElements.php index d6aab86f..6dbc0273 100644 --- a/src/Api/Concerns/InteractsWithElements.php +++ b/src/Api/Concerns/InteractsWithElements.php @@ -12,19 +12,9 @@ trait InteractsWithElements { /** - * Click the link with the given text. + * Click an element using smart selector detection (id, class, data-test, submit, text, etc). */ - public function click(string $text): self - { - $this->guessLocator($text)->click(); - - return $this; - } - - /** - * Click on the specified data-test selector. - */ - public function clickSelector(string $selector): self + public function click(string $selector): self { $this->guessLocator($selector)->click(); diff --git a/tests/Browser/Webpage/ClickSelectorTest.php b/tests/Browser/Webpage/ClickSelectorTest.php deleted file mode 100644 index c2fb9275..00000000 --- a/tests/Browser/Webpage/ClickSelectorTest.php +++ /dev/null @@ -1,22 +0,0 @@ - ' -
-
- Click Me -
-
-
- '); - - $page = visit('/'); - - $page->clickSelector('@test-selector'); - - expect($page->text('#result'))->toBe('Selector Clicked'); -}); diff --git a/tests/Browser/Webpage/ClickTest.php b/tests/Browser/Webpage/ClickTest.php index 0396359e..d0e6d048 100644 --- a/tests/Browser/Webpage/ClickTest.php +++ b/tests/Browser/Webpage/ClickTest.php @@ -73,3 +73,20 @@ '[name$="test"]', 'button[name="test"]', ]); + +it('can click on the element using the data-test selector', function (): void { + Route::get('/', fn (): string => ' +
+
+ Click Me +
+
+
+ '); + + $page = visit('/'); + + $page->click('@test-selector'); + + expect($page->text('#result'))->toBe('Selector Clicked'); +}); From 17617bf356d275e5e96bc917c91437d7f5e96e78 Mon Sep 17 00:00:00 2001 From: dmitritarasov Date: Fri, 17 Apr 2026 18:59:48 +0300 Subject: [PATCH 3/3] fix: test no need form tag --- tests/Browser/Webpage/ClickTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/Browser/Webpage/ClickTest.php b/tests/Browser/Webpage/ClickTest.php index d0e6d048..80bcb458 100644 --- a/tests/Browser/Webpage/ClickTest.php +++ b/tests/Browser/Webpage/ClickTest.php @@ -76,12 +76,10 @@ it('can click on the element using the data-test selector', function (): void { Route::get('/', fn (): string => ' -
-
- Click Me -
-
-
+
+ Click Me +
+
'); $page = visit('/');