0

I'm writing a cypress test that tests a map application. When I click on a specific button, I want to wait for all resources to load on the map.

Currently, the button is making a request to a url: someurl.com/myData/** Where the ** represents dynamic data.

This is what I currently have:

describe('Map Data', () => {
  beforeEach(()=> {
  cy.intercept('GET', 'http://someurl.com/myData/**').as('loadData')  
  cy.visit('/')
})
it('checks for all resources to be loaded', () => {
  cy.get('#loadButton').click()
  cy.wait('@loadData')
})
})

This waits until the first resource was loaded. However, there are many resources from the url and I was wondering if it's possible to wait for at least a certain number of them to load?

Ho'okano
  • 148
  • 4

1 Answers1

4

Intercepts are valid for any number of requests. They are listeners that keep listening, except when the test changes - then they are removed (but are re-setup when you have a beforeEach())

You can just wait for "a certain number"

cy.intercept(...).as('data')
cy.get('#loadButton').click()

let certainNumber = 10
for (let i = 0; i < certainNumber; i++) {
  cy.wait('@loadData')
}

Of course, you have to be certain about the number.

Ho'okano
  • 148
  • 4
  • Thank you so much! That works perfectly. I didn't realize I could use the cy.wait() command inside of a loop like that. –  Aug 16 '23 at 22:52