diff --git a/src/Api/Concerns/MakesElementAssertions.php b/src/Api/Concerns/MakesElementAssertions.php index 0270add7..43809446 100644 --- a/src/Api/Concerns/MakesElementAssertions.php +++ b/src/Api/Concerns/MakesElementAssertions.php @@ -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.", + ); } /** @@ -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); } /** @@ -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); } /** diff --git a/tests/Browser/Webpage/AssertSeeInTest.php b/tests/Browser/Webpage/AssertSeeInTest.php index 8c45298a..416176aa 100644 --- a/tests/Browser/Webpage/AssertSeeInTest.php +++ b/tests/Browser/Webpage/AssertSeeInTest.php @@ -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 => '