Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress assertion Equal and Greater than

Tags:

cypress

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 )
like image 765
varat bhusan Avatar asked May 28 '20 19:05

varat bhusan


People also ask

What is @Cypress assertion?

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.

How to use assert in Chai with cypress?

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.

Why do some of the Cypress commands fail?

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 ".

When to use negative assertion in Cypress?

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.


2 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)
like image 67
Sree.Bh Avatar answered Oct 12 '22 05:10

Sree.Bh


You can also have the length in there

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

like image 23
Metawaa Avatar answered Oct 12 '22 03:10

Metawaa