0

This is my code:

try {   
    cy.get('.hello-bar-contentwrap')
        .should('have.css','padding-top','28px')
        .should('have.css','padding-right','37px')
        .should('have.css','padding-left','37px') }    

What I Intend to achieve is that CSS - Padding bottom should check for a range for ex. From 18px to 21px so that I can pass the case which is as failed below:

Something like this:

.should('have.css','height', expect('48px').to.be.closeTo('47','49'))

Issue screenshot

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Akash
  • 61
  • 1
  • 6

1 Answers1

1

From the docs chaijs closeTo the parameters are numbers, so a little conversion will work

const cssText = '48px'
const numericHeight = +cssText.replace('px', '')
expect(numericHeight).to.be.closeTo(47, 2)      // 2nd param is +/-, not absolute

Specifically your test,

.should('have.css', 'height')
.then(height => +height.replace('px', ''))  // convert
.should('be.closeTo', 47, 2)

This must be the last in the chain, as the subject changes from element to height attribute.

Paolo
  • 3,530
  • 7
  • 21