0

I want read sitemap.xml file and then want to check status of every url present in sitemap. URL present in sitemap are around 20K so I dont want to visit url but just wants to check status and as url count is too large wants to run every url as one test case so that one of test case failure would not affect remaining ones.

Wants to implement above in Cypress

Sayili Arya
  • 103
  • 1
  • 1
  • 6

1 Answers1

0

There is an answer here Cypress.io - sitemap.xml validation test that may start you off.

Instead of cy.visit(url) use cy.request(url), it should be much faster.

it('check each url in the sitemap.xml', () => {

  const results = []

  cy.request('sitemap.xml')
    .then(response => {
      // convert sitemap xml body to an array of urls
      urls = Cypress.$(response.body)
        .find('loc')
        .toArray()
        .map(el => el.innerText)
      return urls
    })
    .then(urls => {
      urls.forEach(url => {
        cy.request({
          url, 
          failOnStatusCode: false      // get status good and bad
        })
        .then(response => {
          results.push({url, statusCode: response.statusCode})
        })
      })
    })

    // use results inside .then()
    cy.then(() => {
      console.log(results)
    })
})

BTW putting each URL in a separate test is a big headache.

The above pattern will give you status codes on good and bad URLS, and will be faster than separate tests.

Fody
  • 23,754
  • 3
  • 20
  • 37