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 )
Cypress Assertion helps us to assert a particular Assertions are validation steps that ensures whether the expected result is equal to the actual result. In test automation, we assert a statement to verify that the test is generating the expected result. If the assertion fails, then the test case fails ensuring that there is a bug.
Cypress uses and wraps Chai assertion library and extensions like Sinon and JQuery. Cypress automatically waits and retries until the assertion is resolved. Assertions can be used to describe how the application should look like. We can use Cypress assertions with combination of waits, retry, block until it reaches the desired state.
The reason for the same is that many of the Cypress commands have in-built assertions or say many of the Cypress commands have requirements that may cause it to fail without needing an explicit assertion. Cypress community names them as " Default Assertions ".
Let us see an example of negative assertion Negative assertion is recommended only in cases to verify that a particular condition is no longer available after a specific action is performed by the application. With Cypress, we can provide additional information or custom message for assertions by using a library of matchers.
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
cy.get('.table > tbody > tr') .should('have.length.greaterThan',1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With