Is this possible to hit single api multiple time in cypress js

Viewed 38

For Example, I have api "localhost:4000/api/register" i want to hit this api 10 times in single test case

2 Answers

Use lodash method Cypress._.times()

Example:

Cypress._.times(10, (k) => {
  it(`register ${k + 1} times`, () => {
    // here the test
  })
})

You can like this also, This is sample one which I used,

const count = 10;
static pollAndWait(count) {
        
        cy.testNetwork().then((response) => {
            expect(response.status).to.eq(200);

            if (response.body.resultSizeEstimate > 0  || count == 0) {
                return;
            }
            else {
               this.testNetwork(--count);
            }
        });
    }
Related