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 <input> elements (except checkbox type ones) 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-3198400
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:
- 3198400-convert-assertions-involving
changes, plain diff MR !317
Comments
Comment #3
mondrakeComment #4
daffie commentedWhen I do a code base search for
$this->xpath('//input[, I still find instances that are not with checkboxes.Comment #5
mondrakeSure, it's not complete yet. Making it visible on the IT.
Comment #6
mondrakeI think the remaining ones should stay.
Comment #7
daffie commentedCould you explain why?
Back to needs work for the unresolved threads.
Comment #8
mondrakeThanks @daffie
#7 because the use of xpath in those cases is needed to build an array of node elements that is then traversed by
foreachconstructs.But happy to fix if I missed anything.
Comment #9
daffie commentedCould you take a look at the class Drupal\Tests\system\Functional\Form\ElementsTableSelectTest on the lines 41 and 58. Should we also do these in this issue? I agree with you on all the other ones that we should not change them.Found the answer myself. We are not doing the checkboxes in this issue.Comment #10
daffie commentedAll code change look good to me.
All instances that should be changed are changed.
A number cannot be changed, because the resulting array is used in some way like in a foreach loop.
For me it is RTBC.
Comment #11
alexpottIf the change to not count the form_build_id hidden fields is valid then we need to document why in the issue summary.
Comment #12
mondrakeThanks, fixed.
Comment #13
daffie commentedAll the points of @alexpott have been addressed.
Back to RTBC.
Comment #14
longwaveElementsTableSelectTest:
We could fix these here? These seem buggy anyway, I think the second argument is used incorrectly.
FormElementMaxlengthTest and FilterBooleanWebTest also look like they could be converted to be a bit cleaner.
Comment #15
mondrakeThanks
#14 I saw that, but could not figure out what it is meant to be tested there... the entire setting of $rows and the foreach seem irrelevant. I think this is a bug that deserves an issue of its own.
FilterBooleanWebTest - not really sure... the xpath there is selecting multiple nodes and then the assertion is on a specific element in the array.
NW for FormElementMaxlengthTest
Comment #16
mondrakeActually, no - FormElementMaxlengthTest is a kernel test, we cannot use WebAssert there
Comment #19
catchGood clean-up again.
Committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!