Uploaded July 2023 | Updated November 2026, 2 days ago
In this video, I show how to get the right cells from the table, parse their text, and then confirm the sum of prices is equal to $8. Find the full recipe at glebbahmutov.com/cypress-examples
function sumCaPrices(state) {
return cy
.get('table#prices tbody tr td:nth-child(2)')
.filter(function (k, el) { return el.innerText.startsWith(state) })
}
sumCaPrices('CA')
.map('innerText')
.mapInvoke('split', '$')
.mapInvoke('at', 1)
.map(Number)
.reduce(function (sum, current) { return sum + current }, 0)
.should('equal', 8)
Tip: cy.map, cy.mapInvoke, cy.print, cy.reduce come from my plugin github.com/bahmutov/cypress-map
In this video, I show how to get the right cells from the table, parse their text, and then confirm the sum of prices is equal to $8. Find the full recipe at glebbahmutov.com/cypress-examples
function sumCaPrices(state) {
return cy
.get('table#prices tbody tr td:nth-child(2)')
.filter(function (k, el) { return el.innerText.startsWith(state) })
}
sumCaPrices('CA')
.map('innerText')
.mapInvoke('split', '$')
.mapInvoke('at', 1)
.map(Number)
.reduce(function (sum, current) { return sum + current }, 0)
.should('equal', 8)
Tip: cy.map, cy.mapInvoke, cy.print, cy.reduce come from my plugin github.com/bahmutov/cypress-map







