Problem/Motivation
We have:
\Drupal\Tests\BrowserTestBase::xpath(), used in browser tests. Returns\Behat\Mink\Element\NodeElement[]\Drupal\KernelTests\AssertContentTrait::xpath(), used in Kernel tests. Returns\SimpleXMLElement[]|false.
This is poor DX, and is going to cause confusion when people convert Browser tests to Kernel tests.
It is also an issue in traits that call $this->xpath but can be used in both Browser and Kernel tests, such as AssertBreadcrumbTrait.
Over at #3583594: Add getUrl() and (renamed) xpath() helpers to HttpKernelUiHelperTrait, the browser test flavour was made available to kernel tests, and to avoid confusion it was renamed to getNodeElementsByXpath().
A similar renaming should be done to the existing methods.
Steps to reproduce
Proposed resolution
Rename:
BrowserTestBase::xpath()togetNodeElementsByXpath()AssertContentTrait::xpath()togetSimpleXmlElementsByXpath()
Remaining tasks
Update AssertContentTrait and its usages.
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3585774
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
joachim commentedThis is unblocked now the other issue is in.
Comment #4
mstrelan commentedCame here from #3517299: Convert functional tests in help module to kernel tests where
AssertBreadcrumbTraitis calling$this->xpathbut is used in both Kernel and Functional tests. Deprecating::xpathand adding the other to BrowserTestBase(via UiHelperTrait)will help.Comment #6
mstrelan commentedI didn't see the novice tag sorry, just came across it and wanted it resolved for 3517299. Worked on the BrowserTestBase part at DrupalSouth contribution day. Will leave AssertContentTrait for someone else, although I wonder if it's better to split to a separate issue given we also need to update all usages at the same time.
Comment #7
mstrelan commentedComment #9
brandonlira commentedHi,
I rebased the MR against latest main and resolved conflicts.
Added getSimpleXmlElementsByXpath() to AssertContentTrait, deprecated xpath(), and updated the Kernel test usages.
Thank you!
Comment #10
dcam commentedThe conversions are straightforward and I don't have any feedback about them. Grep didn't find any additional uses of the old
xpath(). But the deprecation versions are out-of-date. I left suggestions for them.Comment #11
mstrelan commentedAccepted suggestions and updated the CR.
Comment #12
dcam commentedLooks good to me.
Comment #13
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #14
mstrelan commentedRebased, accepted the delete of ShortcutLinksTest from #3586214: Remove the Shortcut module. Restoring status.
Comment #15
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #16
brandonlira commentedRebased the MR against the latest main.
Comment #17
nitinkumar_7 commentedTested the MR : previus changes and rebase the diff is unchanged from what was previously RTBC'd in #12, just a clean rebase against current main (picking up the ShortcutLinksTest removal from #3586214). Deprecation shims in BrowserTestBase::xpath() and AssertContentTrait::xpath() still look correct and all call sites across core still use the right method for their context. Confirmed no leftover unconverted xpath() calls. Restoring RTBC.
Comment #18
longwaveStatusTest at least still has some
xpath()calls.Comment #19
mstrelan commentedUpdated two remaining instances in StatusTest
Comment #20
longwaveCommitted and pushed ea9e2403f44 to main. Thanks!
Doesn't backport cleanly to 11.x, not sure it's worth it now? Marking as fixed but please reopen if you disagree.
Comment #23
mstrelan commentedTo make contrib smoother we should at least backport the new method so we don't need to use DeprecationHelper once 11.5.0 is the minimum supported version.
The deprecation message says deprecated from 11.5.0 so if we don't backport that should be updated to 12.0.0.
Comment #24
jacobupal commentedSeemingly no current work on this a Novice can do, so removing the tag (here in Issue Triage at DrupalCon Rotterdam 2026).
Comment #25
jacobupal commentedComment #28
longwaveThis MR only backports the new methods and basic tests for them, it does not deprecate or convert existing tests.