|
4 | 4 |
|
5 | 5 | namespace Pest\Browser\Playwright; |
6 | 6 |
|
| 7 | +use Pest\Browser\Support\Selector; |
| 8 | + |
7 | 9 | /** |
8 | 10 | * @internal |
9 | 11 | */ |
@@ -109,6 +111,66 @@ public function querySelector(string $selector): ?Element |
109 | 111 | return null; |
110 | 112 | } |
111 | 113 |
|
| 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 | + |
112 | 174 | /** |
113 | 175 | * Clicks the element matching the specified selector. |
114 | 176 | */ |
|
0 commit comments