Basic logic: there is a dropdown with 5 region's options. On each iteration cy clicks an option and should waiting for data on the page will be updated with new data from response (SPA react application)
Can't understand why test fails on the step cy.wait(@getCountry${item.region}
) starting from second iteration?
it('Check all world regions in selector by clicking each option', () => {
cy.get<RegionsT>('@regionsData').then((regionsData) => {
regionsData.regions.forEach((item) => {
cy.intercept('GET', `/region/${item.region}`).as(`getCountry${item.region}`)
countries.openDropdown()
countries.selectDropdownItem(item.region)
cy.wait(`@getCountry${item.region}`).its('response.statusCode').should('eq', 200)
countries.selectCountryByIndex(0).should('contain.text', item.firstCountryName)
})
})
})
I can pass this test with this implementation:
it('Check all world regions in selector by clicking each option', () => {
cy.get<RegionsT>('@regionsData').then((regionsData) => {
regionsData.regions.forEach((item) => {
let prevCountryName = ''
countries
.getFirstCountryName()
.then(($el) => {
prevCountryName = $el.text()
})
.then(() => {
countries.openDropdown()
countries.selectDropdownItem(item.region)
countries.waitUntilCountriesLoaded(prevCountryName)
countries.selectCountryByIndex(0).should('contain.text', item.firstCountryName)
})
})
})
})
but I try to use intercept() method to concise the test. Сould someone explain where the wrong place?
It's strange but the fix in addition "**" to the intercept url:
cy.intercept('GET', `**/region/${item.region}`).as(`getCountry${item.region}`)
This code is working...