diff --git a/src/Concerns/WaitsForElements.php b/src/Concerns/WaitsForElements.php index 9c0b5a70b..2cc7241e9 100644 --- a/src/Concerns/WaitsForElements.php +++ b/src/Concerns/WaitsForElements.php @@ -70,6 +70,25 @@ public function waitUntilMissing($selector, $seconds = null) }, $message); } + /** + * Wait for the given text to be removed. + * + * @param string $text + * @param int $seconds + * @return $this + * @throws \Facebook\WebDriver\Exception\TimeOutException + */ + public function waitUntilMissingText($text, $seconds = null) + { + $text = Arr::wrap($text); + + $message = $this->formatTimeOutMessage('Waited %s seconds for removal of text', implode("', '", $text)); + + return $this->waitUsing($seconds, 100, function () use ($text) { + return ! Str::contains($this->resolver->findOrFail('')->getText(), $text); + }, $message); + } + /** * Wait for the given text to be visible. * diff --git a/tests/WaitsForElementsTest.php b/tests/WaitsForElementsTest.php index c3b66dda0..3b4f33c56 100644 --- a/tests/WaitsForElementsTest.php +++ b/tests/WaitsForElementsTest.php @@ -95,6 +95,19 @@ public function test_can_wait_for_text() $browser->waitForText('Discount: 20%'); } + public function test_can_wait_for_text_to_go_missing() + { + $element = m::mock(stdClass::class); + $element->shouldReceive('getText') + ->times(3) + ->andReturn('Discount: 20%', 'Discount: 20%', 'SOLD OUT!'); + $resolver = m::mock(stdClass::class); + $resolver->shouldReceive('findOrFail')->with('')->andReturn($element); + $browser = new Browser(new stdClass, $resolver); + + $browser->waitUntilMissingText('Discount: 20%'); + } + public function test_wait_for_text_failure_message_containing_a_percent_character() { $element = m::mock(stdClass::class);