1describe('Sitemap', () => {
2 // initialize the url array
3 let urls = []
4
5 // be sure to get the url list before executing any tests
6 before(async () => {
7 // getch the sitemap content
8 const response = await cy.request('sitemap.xml')
9
10 // convert sitemap xml body to an array of urls
11 urls = Cypress.$(response.body)
12 // according to the sitemap.xml spec,
13 // the url value should reside in a <loc /> node
14 // https://www.google.com/sitemaps/protocol.html
15 .find('loc')
16 // map to a js array
17 .toArray()
18 // get the text of the <loc /> node
19 .map(el => el.innerText)
20 })
21
22 it('should succesfully load each url in the sitemap', () => {
23 urls.forEach(cy.visit)
24 })
25})
26