How do I test text is struck out on the page

225 Views Asked by At

On my ecommerce page the price of an item is reduced.

It shows the old price struck out (600.00€) and the new price not struck out (499.00€).

But when I query the page, I just get the text value

cy.get('#normalprice span')
  .invoke('text')
  .should('eq', '600.00€`)

How do I test the text is struck out? I was expecting <s>600.00€</s> but cy.get('#normalprice span s') fails.

1

There are 1 best solutions below

1
Fody On BEST ANSWER

Most likely it's using text-decoration to do the strikethrough.

Try getting the CSS value,

cy.contains('span', '600.00€')
  .invoke('css', 'text-decoration')
  .should('contain', 'line-through')

The strikethrough can be also be applied on a parent, so you may need to add a .parents() selector

cy.contains('span', '600.00€')
  .parents('div')                     // inspect to see where the CSS is applied
  .invoke('css', 'text-decoration')
  .should('contain', 'line-through')