Skip to content

Commit 72f0f71

Browse files
committed
WIP
1 parent 2f2c660 commit 72f0f71

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/Operations/ClickLink.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
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
}

src/PendingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

tests/Browser/Operations/ClickLinkTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66

77
use 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+
});

0 commit comments

Comments
 (0)