Skip to content

Instantly share code, notes, and snippets.

@dannyshain
Last active November 11, 2021 19:25
Show Gist options
  • Save dannyshain/d13c51bf1cb6c1c2507d50a95ba06515 to your computer and use it in GitHub Desktop.
Save dannyshain/d13c51bf1cb6c1c2507d50a95ba06515 to your computer and use it in GitHub Desktop.
it("Verify jsonLD structured data - simple", () => {
// Query the script tag with type application/ld+json
cy.get("script[type='application/ld+json']").then((scriptTag) => {
// we need to parse the JSON-LD from text to a JSON to easily test it
const jsonLD = JSON.parse(scriptTag.text());
// once parsed we can easily test for different data points
expect(jsonLD["@context"]).equal("https://schema.org");
expect(jsonLD.author).length(2);
// Cross-referencing SEO data between the page title and the headline
// in the jsonLD data, great for dynamic data
cy.title().then((currentPageTitle) =>
expect(jsonLD["headline"]).equal(currentPageTitle)
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment