Home > Blockchain >  Cypress how do you export and save every single element and its content from body?
Cypress how do you export and save every single element and its content from body?

Time:01-16

I am trying to compare before and after contents of a webpage. I somehow need to take a snapshop of all the elements and its content of a page and then that same webpage gets upgraded via external Jenkins job. Once the job is completed, I need re-open the same webpage and ensure nothing has been changed in terms of all the contents of all the divs within body.

I've tried this but that only stores all the divs itself from the body and not their contents.

var oldBody = document.createElement( 'html' );
oldBody.innerHTML = request.body 

var newBody = document.createElement( 'html' );
newBody.innerHTML = request.body 

cy.expect(oldBody).to.contain(newBody)

cypress: comparing information in 2 sites

CodePudding user response:

This will give you a simple snapshot of everything in a page

cy.visit('http://example.com');
cy.get('html')
  .then($el => {
    cy.writeFile('./cypress/fixtures/webpage1.html', $el[0].innerHTML)
  })

If you just want the visible parts, cy.get('body') might be better as html gives you <head><meta...> tags that may change for each access.

  • Related