Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Support/GuessLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public function for(string $selector, ?string $value = null): Locator
if (Selector::isDataTest($selector)) {
$id = Selector::escapeForAttributeSelectorOrRegex(str_replace('@', '', $selector), true);

if ($value !== null) {
$value = sprintf('[value=%s]', Selector::escapeForAttributeSelectorOrRegex($value, true));

return $this->page->unstrict(
fn (): Locator => $this->page->locator(
"[data-testid=$id]$value, [data-test=$id]$value",
),
);
}

return $this->page->unstrict(
fn (): Locator => $this->page->locator(
"[data-testid=$id], [data-test=$id]",
Expand Down
16 changes: 16 additions & 0 deletions tests/Browser/Webpage/AssertRadioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@
$page->assertRadioNotSelected('color', 'red');
})->throws(ExpectationFailedException::class);

it('may assert radio is selected by data-testid and value', function (): void {
Route::get('/', fn (): string => '<input type="radio" data-testid="color" name="color" value="red"><input type="radio" data-testid="color" name="color" value="blue" checked>');

$page = visit('/');

$page->assertRadioSelected('@color', 'blue');
});

it('may assert radio is not selected by data-testid and value', function (): void {
Route::get('/', fn (): string => '<input type="radio" data-testid="color" name="color" value="red" checked><input type="radio" data-testid="color" name="color" value="blue">');

$page = visit('/');

$page->assertRadioNotSelected('@color', 'blue');
});

it('may assert all radios in a group are not selected', function (): void {
Route::get('/', fn (): string => '<input type="radio" name="size" value="small"><input type="radio" name="size" value="medium"><input type="radio" name="size" value="large">');

Expand Down