Skip to content

Commit e7c2509

Browse files
Bryce-StabenowBryce Stabenow
and
Bryce Stabenow
authored
Case insensitive assertions (#1073)
* 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]>
1 parent 2eaa14a commit e7c2509

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/Concerns/MakesAssertions.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ public function assertPlainCookieValue($name, $value)
145145
* Assert that the given text is present on the page.
146146
*
147147
* @param string $text
148+
* @param bool $ignoreCase
148149
* @return $this
149150
*/
150-
public function assertSee($text)
151+
public function assertSee($text, $ignoreCase = false)
151152
{
152-
return $this->assertSeeIn('', $text);
153+
return $this->assertSeeIn('', $text, $ignoreCase);
153154
}
154155

155156
/**
@@ -168,16 +169,17 @@ public function assertDontSee($text)
168169
*
169170
* @param string $selector
170171
* @param string $text
172+
* @param bool $ignoreCase
171173
* @return $this
172174
*/
173-
public function assertSeeIn($selector, $text)
175+
public function assertSeeIn($selector, $text, $ignoreCase = false)
174176
{
175177
$fullSelector = $this->resolver->format($selector);
176178

177179
$element = $this->resolver->findOrFail($selector);
178180

179181
PHPUnit::assertTrue(
180-
Str::contains($element->getText(), $text),
182+
Str::contains($element->getText(), $text, $ignoreCase),
181183
"Did not see expected text [{$text}] within element [{$fullSelector}]."
182184
);
183185

src/Concerns/WaitsForElements.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,19 @@ public function waitUntilMissingText($text, $seconds = null)
9595
*
9696
* @param array|string $text
9797
* @param int|null $seconds
98+
* @param bool $ignoreCase
9899
* @return $this
99100
*
100101
* @throws \Facebook\WebDriver\Exception\TimeoutException
101102
*/
102-
public function waitForText($text, $seconds = null)
103+
public function waitForText($text, $seconds = null, $ignoreCase = false)
103104
{
104105
$text = Arr::wrap($text);
105106

106107
$message = $this->formatTimeOutMessage('Waited %s seconds for text', implode("', '", $text));
107108

108-
return $this->waitUsing($seconds, 100, function () use ($text) {
109-
return Str::contains($this->resolver->findOrFail('')->getText(), $text);
109+
return $this->waitUsing($seconds, 100, function () use ($text, $ignoreCase) {
110+
return Str::contains($this->resolver->findOrFail('')->getText(), $text, $ignoreCase);
110111
}, $message);
111112
}
112113

@@ -116,16 +117,17 @@ public function waitForText($text, $seconds = null)
116117
* @param string $selector
117118
* @param array|string $text
118119
* @param int|null $seconds
120+
* @param bool $ignoreCase
119121
* @return $this
120122
*
121123
* @throws \Facebook\WebDriver\Exception\TimeoutException
122124
*/
123-
public function waitForTextIn($selector, $text, $seconds = null)
125+
public function waitForTextIn($selector, $text, $seconds = null, $ignoreCase = false)
124126
{
125127
$message = 'Waited %s seconds for text "'.$this->escapePercentCharacters($text).'" in selector '.$selector;
126128

127-
return $this->waitUsing($seconds, 100, function () use ($selector, $text) {
128-
return $this->assertSeeIn($selector, $text);
129+
return $this->waitUsing($seconds, 100, function () use ($selector, $text, $ignoreCase) {
130+
return $this->assertSeeIn($selector, $text, $ignoreCase);
129131
}, $message);
130132
}
131133

0 commit comments

Comments
 (0)