From 0c020870a04f4df5e6347bd0e1ff0673253c1232 Mon Sep 17 00:00:00 2001 From: Bryce Stabenow Date: Tue, 2 Jan 2024 15:15:46 -0600 Subject: [PATCH 1/3] Adding possibility for case-insensitive text assertions --- src/Concerns/MakesAssertions.php | 10 ++++++---- src/Concerns/WaitsForElements.php | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Concerns/MakesAssertions.php b/src/Concerns/MakesAssertions.php index b508fcdc3..3e4638541 100644 --- a/src/Concerns/MakesAssertions.php +++ b/src/Concerns/MakesAssertions.php @@ -145,11 +145,12 @@ public function assertPlainCookieValue($name, $value) * Assert that the given text is present on the page. * * @param string $text + * @param bool $ignoreCase * @return $this */ - public function assertSee($text) + public function assertSee($text, $ignoreCase = false) { - return $this->assertSeeIn('', $text); + return $this->assertSeeIn('', $text, $ignoreCase); } /** @@ -168,16 +169,17 @@ public function assertDontSee($text) * * @param string $selector * @param string $text + * @param bool $ignoreCase * @return $this */ - public function assertSeeIn($selector, $text) + public function assertSeeIn($selector, $text, $ignoreCase = false) { $fullSelector = $this->resolver->format($selector); $element = $this->resolver->findOrFail($selector); PHPUnit::assertTrue( - Str::contains($element->getText(), $text), + Str::contains($element->getText(), $text, $ignoreCase), "Did not see expected text [{$text}] within element [{$fullSelector}]." ); diff --git a/src/Concerns/WaitsForElements.php b/src/Concerns/WaitsForElements.php index 7c5ed0c01..3513d4b3e 100644 --- a/src/Concerns/WaitsForElements.php +++ b/src/Concerns/WaitsForElements.php @@ -116,16 +116,17 @@ public function waitForText($text, $seconds = null) * @param string $selector * @param array|string $text * @param int|null $seconds + * @param bool $ignoreCase * @return $this * * @throws \Facebook\WebDriver\Exception\TimeoutException */ - public function waitForTextIn($selector, $text, $seconds = null) + public function waitForTextIn($selector, $text, $seconds = null, $ignoreCase = false) { $message = 'Waited %s seconds for text "'.$this->escapePercentCharacters($text).'" in selector '.$selector; return $this->waitUsing($seconds, 100, function () use ($selector, $text) { - return $this->assertSeeIn($selector, $text); + return $this->assertSeeIn($selector, $text, $ignoreCase); }, $message); } From 4722376e02569a73fee5046fb338fb4813502d95 Mon Sep 17 00:00:00 2001 From: Bryce Stabenow Date: Tue, 2 Jan 2024 15:28:30 -0600 Subject: [PATCH 2/3] add case insensitive option for waitForText --- src/Concerns/WaitsForElements.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Concerns/WaitsForElements.php b/src/Concerns/WaitsForElements.php index 3513d4b3e..20097ee3d 100644 --- a/src/Concerns/WaitsForElements.php +++ b/src/Concerns/WaitsForElements.php @@ -95,18 +95,19 @@ public function waitUntilMissingText($text, $seconds = null) * * @param array|string $text * @param int|null $seconds + * @param bool $ignoreCase * @return $this * * @throws \Facebook\WebDriver\Exception\TimeoutException */ - public function waitForText($text, $seconds = null) + public function waitForText($text, $seconds = null, $ignoreCase = false) { $text = Arr::wrap($text); $message = $this->formatTimeOutMessage('Waited %s seconds for text', implode("', '", $text)); return $this->waitUsing($seconds, 100, function () use ($text) { - return Str::contains($this->resolver->findOrFail('')->getText(), $text); + return Str::contains($this->resolver->findOrFail('')->getText(), $text, $ignoreCase); }, $message); } From f80b93391d9a3c9789c6092f9da29e312fabeeac Mon Sep 17 00:00:00 2001 From: Bryce Stabenow Date: Tue, 2 Jan 2024 17:11:47 -0600 Subject: [PATCH 3/3] fix oversight in use statements --- src/Concerns/MakesAssertions.php | 4 ++-- src/Concerns/WaitsForElements.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Concerns/MakesAssertions.php b/src/Concerns/MakesAssertions.php index 3e4638541..8e6c2067f 100644 --- a/src/Concerns/MakesAssertions.php +++ b/src/Concerns/MakesAssertions.php @@ -145,7 +145,7 @@ public function assertPlainCookieValue($name, $value) * Assert that the given text is present on the page. * * @param string $text - * @param bool $ignoreCase + * @param bool $ignoreCase * @return $this */ public function assertSee($text, $ignoreCase = false) @@ -169,7 +169,7 @@ public function assertDontSee($text) * * @param string $selector * @param string $text - * @param bool $ignoreCase + * @param bool $ignoreCase * @return $this */ public function assertSeeIn($selector, $text, $ignoreCase = false) diff --git a/src/Concerns/WaitsForElements.php b/src/Concerns/WaitsForElements.php index 20097ee3d..54be34931 100644 --- a/src/Concerns/WaitsForElements.php +++ b/src/Concerns/WaitsForElements.php @@ -106,7 +106,7 @@ public function waitForText($text, $seconds = null, $ignoreCase = false) $message = $this->formatTimeOutMessage('Waited %s seconds for text', implode("', '", $text)); - return $this->waitUsing($seconds, 100, function () use ($text) { + return $this->waitUsing($seconds, 100, function () use ($text, $ignoreCase) { return Str::contains($this->resolver->findOrFail('')->getText(), $text, $ignoreCase); }, $message); } @@ -126,7 +126,7 @@ public function waitForTextIn($selector, $text, $seconds = null, $ignoreCase = f { $message = 'Waited %s seconds for text "'.$this->escapePercentCharacters($text).'" in selector '.$selector; - return $this->waitUsing($seconds, 100, function () use ($selector, $text) { + return $this->waitUsing($seconds, 100, function () use ($selector, $text, $ignoreCase) { return $this->assertSeeIn($selector, $text, $ignoreCase); }, $message); }