Search code examples
cypresssitemaplibxml-js

Cypress.io - sitemap.xml validation test


:) I chose for automated testing a tool Cypress.io. I need some tests for my sitemap.xml document and I dont know how to do that :(

I have tried install an npm package libxmljs

npm install libxmljs --save

and load it as plugin in cypress/plugins/index.js

const libxmljs = require('libxmljs');

But there is a problem with this. It shows an error

The plugins file is missing or invalid.

Your pluginsFile is set to /home/my-app/cypress/plugins/index.js, but
either the file is missing,
it contains a syntax error, or threw an error when required.

The pluginsFile must be a .js or .coffee file.

Please fix this, or set pluginsFile to false if a plugins file is not
necessary for your project.

Error: The module '/home/my-app/node_modules/libxmljs/build/Release/xmljs.node'

Please help me, how can I use libxmljs in Cypress.io or how i should write tests for Sitemap.xml in this end-to-end testing tool.

Thanks for your time! :)


Solution

  • If you want to use libxmljs to parse your sitemap you should

    • read the sitemap itself with cy.request
    • add a custom task to Cypress (because libxmljs is a node library, cy.task is the only way to consume Node.js scripts from your Cypress tests)
    • returns the parsed data from your task
    • assert about it in a Cypress test

    Those are the high-level steps you need to do 😉