Cypress assertion Equal and Greater than

Viewed 20157

how to write the assertion in cypress with greater than equal to.if my value = 5000.00 , and i have to write test case,if my value == 5000.00 than Pass and if my value >5000.00 than also pass, how to write it correctly to pass

my_value= 5000.00
        expect(my_value).to.equal(5000.00)
        cy.wrap(my_value).should('be.greaterThan',5000.00 )
3 Answers

Refer here:

const my_value = 5000.00;

cy.wrap(my_value).should('be.gt', 4999.99); // greater than
cy.wrap(my_value).should('be.gte', 5000); // greater than equal to

cy.wrap(my_value).should('be.lt', 5000.1);// less than
cy.wrap(my_value).should('be.lte', 5000); // less than equal to

When verifying from DOM element, we need to parse the value:

cy.get('div').invoke('text').then(parseFloat).should('be.gt', 10)

You can also have the length in there

// With `.greaterThan` chainer
cy.get('.table > tbody > tr').should('have.length.greaterThan', 1)

// With `least` chainer (meaning greater then or equal to)
cy.get('.table > tbody > tr').should('have.length.least', 1)

See more chainers and their aliases in the official docs.

Please try something like:

    const my_value = 5000.00;
    cy.get(ELEMENT).invoke('text').then(parseFloat).should('be.gte', my_value)
  • .should('be.gt') is for greater than
  • .should('be.gte') is for greater than and equal to
Related