Skip to content

Commit

Permalink
Case insensitive assertions (#1073)
Browse files Browse the repository at this point in the history
* Adding possibility for case-insensitive text assertions

* add case insensitive option for waitForText

* fix oversight in use statements

---------

Co-authored-by: Bryce Stabenow <[email protected]>
  • Loading branch information
Bryce-Stabenow and Bryce Stabenow authored Jan 3, 2024
1 parent 2eaa14a commit e7c2509
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/Concerns/MakesAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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}]."
);

Expand Down
14 changes: 8 additions & 6 deletions src/Concerns/WaitsForElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 $this->waitUsing($seconds, 100, function () use ($text, $ignoreCase) {
return Str::contains($this->resolver->findOrFail('')->getText(), $text, $ignoreCase);
}, $message);
}

Expand All @@ -116,16 +117,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->waitUsing($seconds, 100, function () use ($selector, $text, $ignoreCase) {
return $this->assertSeeIn($selector, $text, $ignoreCase);
}, $message);
}

Expand Down

0 comments on commit e7c2509

Please sign in to comment.