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() to getNodeElementsByXpath()
  • AssertContentTrait::xpath() to getSimpleXmlElementsByXpath()

Remaining tasks

Update AssertContentTrait and its usages.

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3585774

Command icon 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

joachim created an issue. See original summary.

joachim’s picture

Status: Postponed » Active
Issue tags: +Novice
Related issues: +#3583594: Add getUrl() and (renamed) xpath() helpers to HttpKernelUiHelperTrait

This is unblocked now the other issue is in.

mstrelan made their first commit to this issue’s fork.

mstrelan’s picture

Came here from #3517299: Convert functional tests in help module to kernel tests where AssertBreadcrumbTrait is calling $this->xpath but is used in both Kernel and Functional tests. Deprecating ::xpath and adding the other to BrowserTestBase (via UiHelperTrait) will help.

mstrelan’s picture

Status: Active » Needs work
Issue tags: +DrupalSouth 2026

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

mstrelan’s picture

Issue summary: View changes

brandonlira made their first commit to this issue’s fork.

brandonlira’s picture

Status: Needs work » Needs review

Hi,
I rebased the MR against latest main and resolved conflicts.

Added getSimpleXmlElementsByXpath() to AssertContentTrait, deprecated xpath(), and updated the Kernel test usages.

Thank you!

dcam’s picture

Status: Needs review » Needs work

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

mstrelan’s picture

Status: Needs work » Needs review

Accepted suggestions and updated the CR.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

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

mstrelan’s picture

Status: Needs work » Reviewed & tested by the community

Rebased, accepted the delete of ShortcutLinksTest from #3586214: Remove the Shortcut module. Restoring status.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

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

brandonlira’s picture

Status: Needs work » Needs review

Rebased the MR against the latest main.

nitinkumar_7’s picture

Status: Needs review » Reviewed & tested by the community

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

longwave’s picture

Status: Reviewed & tested by the community » Needs work

StatusTest at least still has some xpath() calls.

mstrelan’s picture

Status: Needs work » Reviewed & tested by the community

Updated two remaining instances in StatusTest

longwave’s picture

Status: Reviewed & tested by the community » Fixed

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

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • longwave committed ea9e2403 on main
    test: #3585774 rename xpath() methods in tests
    
    By: joachim
    By: mstrelan...
mstrelan’s picture

Version: main » 11.x-dev
Status: Fixed » Patch (to be ported)

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

jacobupal’s picture

Seemingly no current work on this a Novice can do, so removing the tag (here in Issue Triage at DrupalCon Rotterdam 2026).

jacobupal’s picture

Issue tags: -Novice

longwave-bot made their first commit to this issue’s fork.

longwave’s picture

Status: Patch (to be ported) » Needs review

This MR only backports the new methods and basic tests for them, it does not deprecate or convert existing tests.