Filter a List of Elements Using isTrue
This tutorial uses the isTrue
matcher to filter a list of Trailhead units to show only visible (incomplete) units.
The visibleTrailUnits
element in trailheadProgress.utam.json
uses the example-trail-unit
selector to identify all the units. The filter matches all the elements that return true
for the isVisible
basic action. Elements that match are returned.
"elements": [
{
"name": "visibleTrailUnits",
"public": true,
"selector": {
"css": "example-trail-unit",
"returnAll": true
},
"filter": {
"apply": "isVisible",
"matcher": {
"type": "isTrue"
}
}
}
]
The test calls getVisibleTrailUnits()
to get the visible elements. The test then asserts that the number of elements matches the expected number of visible units.
The test code is simple because most of the work is done declaratively in the page object using the power of filters.