File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed
Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 1616 */
1717 public function __construct (
1818 private string $ text ,
19+ private string $ selector = 'a ' ,
1920 ) {
2021 //
2122 }
2223
2324 public function compile (): string
2425 {
25- return sprintf ( "await page.locator('a ').filter({ hasText: /%s /i }).click(); " , $ this -> text ) ;
26+ return "await page.locator(' { $ this -> selector } ').filter({ hasText: / { $ this -> text } /i }).click(); " ;
2627 }
2728}
Original file line number Diff line number Diff line change @@ -72,9 +72,9 @@ public function toNotHaveTitle(string $title): self
7272 /**
7373 * Clicks some text on the page.
7474 */
75- public function clickLink (string $ text ): self
75+ public function clickLink (string $ text, string $ selector = ' a ' ): self
7676 {
77- $ this ->operations [] = new Operations \ClickLink ($ text );
77+ $ this ->operations [] = new Operations \ClickLink ($ text, $ selector );
7878
7979 return $ this ;
8080 }
Original file line number Diff line number Diff line change 66
77use function Pest \Browser \visit ;
88
9- it ('clicks a link ' , function (): void {
9+ it ('clicks a link using its text ' , function (): void {
1010 visit ('https://laravel.com ' )
1111 ->clickLink ('Get Started ' );
1212
1313 expect (file_get_contents (Compiler::TEST_PATH ))
1414 ->toContain ("await page.locator('a').filter({ hasText: /Get Started/i }).click(); " );
1515});
16+
17+ it ('clicks a link using its text and a given selector ' , function (): void {
18+ visit ('https://laravel.com ' )
19+ ->clickLink ('Get Started ' , 'a.border-red-500 ' );
20+
21+ expect (file_get_contents (Compiler::TEST_PATH ))
22+ ->toContain ("await page.locator('a.border-red-500').filter({ hasText: /Get Started/i }).click(); " );
23+ });
You can’t perform that action at this time.
0 commit comments