Skip to content

Commit

Permalink
first tests with structured-data-testing-tool
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardogiorato committed Aug 12, 2021
1 parent 3a0c03c commit 0ddf0ba
Show file tree
Hide file tree
Showing 5 changed files with 578 additions and 17 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# TODO of things to do for this project

* Test JSON-LD metadata from pages with simple plugin thanks to: structured-data-testing-tool
* Social Logins: https://github.com/lirantal/cypress-social-logins
* Proxy: https://docs.cypress.io/guides/references/proxy-configuration
* Test Email mailslurp: https://github.com/mailslurp/examples/tree/master/javascript-cypress-js
Expand All @@ -11,6 +12,5 @@
* Design Icons and Grouping Icons for the different tests
* Create Custom Commands to reduce duplicated code!
* Env and DotEnv with parameter: https://github.com/morficus/cypress-dotenv
* Use Esbuild Preprocessor: https://github.com/bahmutov/cypress-esbuild-preprocessor
* Join Ambassador program: https://www.cypress.io/ambassadors/
* Add project to https://github.com/brunopulis/awesome-cypress
50 changes: 50 additions & 0 deletions cypress/integration/apple-jsonld.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
describe("Apple Structured Data, Schema.org or JSON-LD", () => {
it("apple homepage has WebPage, Organization and Website ", () => {
cy.visit("https://www.apple.com");
cy.task("structuredData", {
url: "https://www.apple.com",
schemas: ["WebPage", "Organization", "WebSite"],
}).then((result) => {
expect(result.passed.length).to.equal(3);
});
});
it("apple iphone 12 has BreadcrumbList and Product ", () => {
cy.visit("https://www.apple.com/iphone-12");
cy.task("structuredData", {
url: "https://www.apple.com/iphone-12",
schemas: ["BreadcrumbList", "Product"],
}).then((result) => {
expect(result.passed.length).to.equal(2);
expect(result.passed[0].schema).to.equal("BreadcrumbList");
expect(result.passed[1].schema).to.equal("Product");
});
});
it("apple iphone 12 shop page has BreadcrumbList, Product and FAQPage ", () => {
cy.task("structuredData", {
url: "https://www.apple.com/shop/buy-iphone/iphone-12",
schemas: ["BreadcrumbList", "Product", "FAQPage"],
}).then((result) => {
expect(result.passed.length).to.equal(3);
expect(result.passed[0].schema).to.equal("BreadcrumbList");
expect(result.passed[1].schema).to.equal("Product");
expect(result.passed[2].schema).to.equal("FAQPage");
});
});
it("apple latest newsroom article has NewsArticle and BreadcrumbList ", () => {
cy.visit("https://www.apple.com/newsroom/");
cy.get("#everydayfeed > .section-content > .section-tiles")
.find("li")
.first()
.click();
cy.location().then((location) => {
cy.task("structuredData", {
url: location.href,
schemas: ["NewsArticle", "BreadcrumbList"],
}).then((result) => {
expect(result.passed.length).to.equal(2);
expect(result.passed[0].schema).to.equal("NewsArticle");
expect(result.passed[1].schema).to.equal("BreadcrumbList");
});
});
});
});
35 changes: 21 additions & 14 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
const { structuredDataTest } = require("structured-data-testing-tool");
const {
Google,
Twitter,
Facebook,
} = require("structured-data-testing-tool/presets");

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {};
module.exports = (on, config) => {
on("task", {
async structuredData({ url, schemas = [], presets = [] }) {
const result = await structuredDataTest(url, {
schemas: schemas,
presets: presets,
auto: false,
}).catch((err) => {
console.warn(err);
return {};
});
return result;
},
});
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"cypress": "^8.2.0",
"junit-report-merger": "^3.0.0",
"structured-data-testing-tool": "^4.5.0",
"xml-js": "^1.6.11"
}
}
Loading

0 comments on commit 0ddf0ba

Please sign in to comment.