I want to write Cypress tests for a website that is being loaded as an iFrame in a parent environment. The parent environment injects metatags when loading the site, and I need to replicate this functionality in Cypress.
Do to so, I need to fetch the contents of a URL passed by a test runner, modify the <head></head>
of the HTML to add meta tags like this:
metaTag.setAttribute("dark-mode", "true");
then load the site with the metadata. However, if I fetch the contents, add metadata, but then run cy.visit(URL)
, only the unmodified site is loaded.
I know Cypress allows accessing metatags, but does it support injecting them?
2
Answers
Thanks to @TesterDick's suggestion, I was able to get the following to work:
This results in the page loading with the correct metadata set.
You could add headers in the
onLoad
event ofcy.visit()
.