From 77e77c40bdb0ecce877b9e4cab43ca6ec6f9ce1e Mon Sep 17 00:00:00 2001 From: Sjors Date: Wed, 18 Dec 2019 14:29:48 +0100 Subject: [PATCH] add waitUntilMissingText --- src/Concerns/WaitsForElements.php | 19 +++++++++++++++++++ tests/WaitsForElementsTest.php | 13 +++++++++++++ 2 files changed, 32 insertions(+) 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);