You are here

public function BrowserTestBaseTest::testXpathAsserts in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testXpathAsserts()
  2. 9 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testXpathAsserts()

Tests legacy field asserts which use xpath directly.

File

core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php, line 274

Class

BrowserTestBaseTest
Tests BrowserTestBase functionality.

Namespace

Drupal\FunctionalTests

Code

public function testXpathAsserts() {
  $this
    ->drupalGet('test-field-xpath');
  $this
    ->assertSession()
    ->elementTextContains('xpath', '//table/tbody/tr[2]/td[1]', 'one');
  $this
    ->assertSession()
    ->fieldValueEquals('edit-name', 'Test name');
  $this
    ->assertSession()
    ->fieldValueEquals('edit-options', '2');
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//notexisting');
  $this
    ->assertSession()
    ->fieldValueNotEquals('edit-name', 'wrong value');

  // Test that the assertion fails correctly.
  try {
    $this
      ->assertSession()
      ->fieldExists('notexisting');
    $this
      ->fail('The "notexisting" field was found.');
  } catch (ExpectationException $e) {

    // Expected exception; just continue testing.
  }
  try {
    $this
      ->assertSession()
      ->fieldNotExists('edit-name');
    $this
      ->fail('The "edit-name" field was not found.');
  } catch (ExpectationException $e) {

    // Expected exception; just continue testing.
  }
}