function BrowserTestBaseTest::testXpathAsserts
Same name in other branches
- 9 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testXpathAsserts()
- 10 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testXpathAsserts()
- 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 266
Class
- BrowserTestBaseTest
- Tests BrowserTestBase functionality.
Namespace
Drupal\FunctionalTestsCode
public function testXpathAsserts() {
$this->drupalGet('test-field-xpath');
$this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL);
$this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one');
$this->assertFieldByXPath('//table/tbody/tr[2]/td[1]', 'one');
$this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'Test name');
$this->assertFieldByXPath("//input[@id = 'edit-name']", 'Test name');
$this->assertFieldsByValue($this->xpath("//select[@id = 'edit-options']"), '2');
$this->assertFieldByXPath("//select[@id = 'edit-options']", '2');
$this->assertNoFieldByXPath('//notexisting');
$this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value');
// Test that the assertion fails correctly.
try {
$this->assertFieldByXPath("//input[@id = 'notexisting']");
$this->fail('The "notexisting" field was found.');
} catch (ExpectationFailedException $e) {
// Expected exception; just continue testing.
}
try {
$this->assertNoFieldByXPath("//input[@id = 'edit-name']");
$this->fail('The "edit-name" field was not found.');
} catch (ExpectationException $e) {
// Expected exception; just continue testing.
}
try {
$this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'not the value');
$this->fail('The "edit-name" field is found with the value "not the value".');
} catch (ExpectationFailedException $e) {
// Expected exception; just continue testing.
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.