Problem/Motivation

In #3167880: [meta] Convert assertions involving use of xpath to WebAssert, where possible we identified that use of $this->xpath() can be dangerous as we aren't always testing what we expect to test. In WebAssert we have more appropriate methods to find and assert HTML elements, so we should use them where possible.

This issue is scoped to find XPath selectors for <div> elements and convert those where possible.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3203476

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

mondrake created an issue. See original summary.

mondrake’s picture

Title: Convert assertions involving use of xpath on divs to WebAssert » [WIP] Convert assertions involving use of xpath on divs to WebAssert
Status: Active » Needs work
mondrake’s picture

Title: [WIP] Convert assertions involving use of xpath on divs to WebAssert » Convert assertions involving use of xpath on divs to WebAssert
Status: Needs work » Needs review

AFAICS the remaining instances (regex: xpath\(.*\/div) are either in Kernel tests or part of more complex loops on results of xpath.

mondrake’s picture

Assigned: mondrake » Unassigned
longwave’s picture

Status: Needs review » Needs work

This looks pretty good, a few little nits but nothing major - let me know what you think about the followup ideas as well!

mondrake’s picture

Status: Needs work » Needs review

Thanks, fixed as appropriate. I agree changing some Xpath to Css would make things better readable, but would suggest a followup to be postponed on #3167880: [meta] Convert assertions involving use of xpath to WebAssert, where possible, to avoid moving targets.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, re-reviewed and all looks good now. Agree that any followups to clean up selectors should wait until we have done all these WebAssert conversions.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

There are outstanding comments to resolve on the MR.

mondrake’s picture

How about adding a WebAssert::elementTextEquals() method and its negative, instead?

longwave’s picture

@mondrake I think that's a good idea to move this forward

mondrake’s picture

Assigned: Unassigned » mondrake
Status: Needs review » Needs work

On this

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
longwave’s picture

elementTextEquals() and the related changes look great, but I question the usefulness of elementTextDoesNotEqual() especially as it's not needed here.

mondrake’s picture

See MR

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Looking good, all review points addressed.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

We should add a CR for the new ::elementTextEquals() method, otherwise this looks like good cleanup lots of assertCount() moved to more specific assertions etc.

mondrake’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record
longwave’s picture

Thanks @mondrake!

  • catch committed 9c2bfa8 on 9.2.x
    Issue #3203476 by mondrake, longwave, alexpott: Convert assertions...

  • catch committed db20cde on 9.1.x
    Issue #3203476 by mondrake, longwave, alexpott: Convert assertions...
catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.