Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive assertions #1073

Merged
Merged
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: 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