Skip to content

Commit d0aff66

Browse files
committed
feat: add methods to find elements by role, test ID, alt text, label, placeholder, text, and title in Frame class
1 parent 3e7f010 commit d0aff66

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

src/Playwright/Frame.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Pest\Browser\Playwright;
66

7+
use Pest\Browser\Support\Selector;
8+
79
/**
810
* @internal
911
*/
@@ -109,6 +111,66 @@ public function querySelector(string $selector): ?Element
109111
return null;
110112
}
111113

114+
/**
115+
* Finds an element by the specified role.
116+
*
117+
* @param array<string, string|bool> $params
118+
*/
119+
public function getByRole(string $role, array $params): ?Element
120+
{
121+
return $this->querySelector(Selector::getByRoleSelector($role, $params));
122+
}
123+
124+
/**
125+
* Finds an element by test ID.
126+
*/
127+
public function getByTestId(string $testId): ?Element
128+
{
129+
$testIdAttributeName = 'data-testid';
130+
131+
return $this->querySelector(Selector::getByTestIdSelector($testIdAttributeName, $testId));
132+
}
133+
134+
/**
135+
* Finds an element by alt text.
136+
*/
137+
public function getByAltText(string $text, bool $exact = false): ?Element
138+
{
139+
return $this->querySelector(Selector::getByAltTextSelector($text, $exact));
140+
}
141+
142+
/**
143+
* Finds an element by label text.
144+
*/
145+
public function getByLabel(string $text, bool $exact = false): ?Element
146+
{
147+
return $this->querySelector(Selector::getByLabelSelector($text, $exact));
148+
}
149+
150+
/**
151+
* Finds an element by placeholder text.
152+
*/
153+
public function getByPlaceholder(string $text, bool $exact = false): ?Element
154+
{
155+
return $this->querySelector(Selector::getByPlaceholderSelector($text, $exact));
156+
}
157+
158+
/**
159+
* Finds an element by its text content.
160+
*/
161+
public function getByText(string $text, bool $exact = false): ?Element
162+
{
163+
return $this->querySelector(Selector::getByTextSelector($text, $exact));
164+
}
165+
166+
/**
167+
* Finds an element by its title attribute.
168+
*/
169+
public function getByTitle(string $text, bool $exact = false): ?Element
170+
{
171+
return $this->querySelector(Selector::getByTitleSelector($text, $exact));
172+
}
173+
112174
/**
113175
* Clicks the element matching the specified selector.
114176
*/

0 commit comments

Comments
 (0)