diff --git a/src/commands/check-sitemap-exists.ts b/src/commands/check-sitemap-exists.ts new file mode 100644 index 0000000..e625f91 --- /dev/null +++ b/src/commands/check-sitemap-exists.ts @@ -0,0 +1,29 @@ +/* eslint-disable tsdoc/syntax */ +/** + * Check Sitemap Exists. + * + * @example + * Use the command without any argument, sitemap.xml will be used: + * ``` + * cy.checkSitemap() + * ``` + * + * @example + * Use the command with custom sitemap path: + * ``` + * cy.checkSitemap( '/alternative-sitemap.xml') + * ``` + */ + +export const checkSitemap = (sitemap_url = '/sitemap.xml'): void => { + cy.request(sitemap_url).then(response => { + if (response.status === 200) { + cy.log('Sitemap exists'); + } else { + cy.log('Sitemap does not exist'); + // Send an alert to the team + // You can use a messaging service like Slack or email to send an alert + cy.task('sendAlert', 'Sitemap has disappeared'); + } + }); +}; diff --git a/src/index.ts b/src/index.ts index 44d3a1d..a711e7e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,7 @@ import { logout } from './commands/logout'; import { login } from './commands/login'; import { createPost } from './commands/create-post'; import { uploadMedia } from './commands/upload-media'; +import { checkSitemap } from './commands/check-sitemap-exists'; declare global { namespace Cypress { @@ -46,6 +47,7 @@ declare global { uploadMedia: typeof uploadMedia; logout: typeof logout; login: typeof login; + checkSitemap: typeof checkSitemap; } } } @@ -74,3 +76,4 @@ Cypress.Commands.add('createPost', createPost); Cypress.Commands.add('uploadMedia', uploadMedia); Cypress.Commands.add('logout', logout); Cypress.Commands.add('login', login); +Cypress.Commands.add('checkSitemap', checkSitemap); diff --git a/tests/cypress/e2e/check-sitemap-exists.test.js b/tests/cypress/e2e/check-sitemap-exists.test.js new file mode 100644 index 0000000..76ad827 --- /dev/null +++ b/tests/cypress/e2e/check-sitemap-exists.test.js @@ -0,0 +1,5 @@ +describe('Command: checkSitemap', () => { + it('Test sitemap existence', () => { + cy.checkSitemap(); + }); +});