public function WebAssert::pageContainsNoDuplicateId in Drupal 9
Asserts that each HTML ID is used for just a single element on the page.
Throws
\Behat\Mink\Exception\ExpectationException
File
- core/
tests/ Drupal/ Tests/ WebAssert.php, line 744
Class
- WebAssert
- Defines a class with methods for asserting presence of elements during tests.
Namespace
Drupal\TestsCode
public function pageContainsNoDuplicateId() {
$seen_ids = [];
foreach ($this->session
->getPage()
->findAll('xpath', '//*[@id]') as $element) {
$id = $element
->getAttribute('id');
if (isset($seen_ids[$id])) {
throw new ExpectationException(sprintf('The page contains a duplicate HTML ID "%s".', $id), $this->session
->getDriver());
}
$seen_ids[$id] = TRUE;
}
}