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
18 changes: 14 additions & 4 deletions src/Api/Concerns/MakesElementAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,19 @@ public function assertSeeIn(string $selector, string|int|float $text): Webpage

$locator = $this->guessLocator($selector);

expect($locator->getByText($text)->isVisible())->toBeTrue("Expected to see text [{$text}] within element [{$selector}] on the page initially with the url [{$this->initialUrl}], but it was not found or not visible.");
$entries = $this->page->unstrict(fn () => $locator->getByText($text));

return $this;
foreach ($entries->all() as $entry) {
if ($entry->isVisible()) {
expect(true)->toBeTrue();

return $this;
}
}

throw new ExpectationFailedException(
"Expected to see text [{$text}] within element [{$selector}] on the page initially with the url [{$this->initialUrl}], but it was not found or not visible.",
);
}

/**
Expand Down Expand Up @@ -453,7 +463,7 @@ public function assertAriaAttribute(string $selector, string $attribute, string|
{
$value = (string) $value;

return $this->assertAttribute($selector, 'aria-'.$attribute, $value);
return $this->assertAttribute($selector, 'aria-' . $attribute, $value);
}

/**
Expand All @@ -463,7 +473,7 @@ public function assertDataAttribute(string $selector, string $attribute, string|
{
$value = (string) $value;

return $this->assertAttribute($selector, 'data-'.$attribute, $value);
return $this->assertAttribute($selector, 'data-' . $attribute, $value);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Browser/Webpage/AssertSeeInTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@

$page->assertDontSeeIn('#content', 'Hello World');
})->throws(ExpectationFailedException::class);

it('may assert text is in a selector when contains multiple', function (): void {
Route::get('/', fn (): string => '<div data-test="content"><span>Hello</span><span>Hello</span><span>Hello</span></div>');

$page = visit('/');

$page->assertSeeIn('@content', 'Hello');
});