You are here

public function WebAssert::elementTextEquals in Drupal 9

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 991

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);
}