function BrowserTestBaseTest::testXpathAsserts
Same name in other branches
- 9 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testXpathAsserts()
- 8.9.x core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testXpathAsserts()
- 10 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 230
Class
- BrowserTestBaseTest
- Tests BrowserTestBase functionality.
Namespace
Drupal\FunctionalTestsCode
public function testXpathAsserts() : void {
$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', '//nonexisting');
$this->assertSession()
->fieldValueNotEquals('edit-name', 'wrong value');
// Test that the assertion fails correctly.
try {
$this->assertSession()
->fieldExists('nonexisting');
$this->fail('The "nonexisting" field was found.');
} catch (ExpectationException) {
// Expected exception; just continue testing.
}
try {
$this->assertSession()
->fieldNotExists('edit-name');
$this->fail('The "edit-name" field was not found.');
} catch (ExpectationException) {
// Expected exception; just continue testing.
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.