function BrowserTestBaseTest::testXpathAsserts

Same name in other branches
  1. 8.9.x core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testXpathAsserts()
  2. 10 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testXpathAsserts()
  3. 11.x 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 378

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.
    }
}

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