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

[5.x] add "waitUntilMissingText" #706

Merged
merged 1 commit into from
Dec 18, 2019
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
19 changes: 19 additions & 0 deletions src/Concerns/WaitsForElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure to always add a whiteline before the @throws annotation.

*/
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.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/WaitsForElementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down