function WebAssert::elementTextEquals

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/WebAssert.php \Drupal\Tests\WebAssert::elementTextEquals()
  2. 10 core/tests/Drupal/Tests/WebAssert.php \Drupal\Tests\WebAssert::elementTextEquals()

Asserts a specific element's text equals an expected text.

Parameters

string $selectorType: Element selector type (css, xpath).

string|array $selector: Element selector.

string $text: Expected text.

File

core/tests/Drupal/Tests/WebAssert.php, line 803

Class

WebAssert
Defines a class with methods for asserting presence of elements during tests.

Namespace

Drupal\Tests

Code

public function elementTextEquals(string $selectorType, $selector, string $text) : void {
    $selector_string = is_array($selector) ? '[' . implode(', ', $selector) . ']' : $selector;
    $message = "Failed asserting that the text of the element identified by '{$selector_string}' equals '{$text}'.";
    $constraint = new IsEqual($text);
    Assert::assertThat($this->elementExists($selectorType, $selector)
        ->getText(), $constraint, $message);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.