Przemek Suchodolski
@przemuh
🇰🇷 korpo, 🇵🇱 software-house, 🇺🇸 startup/korpo
Musician amateur 🎸 🥁 🎹 (soundcloud.com/przemuh)
it("should have a proper className", () => {
const myComponent = render();
expect(myComponent).toHaveClass("pink-blink");
})
.parent {
.pink-blink {
color: red;
animation: none;
}
}
describe("Cypress test suite", () => {
it("test case", () => {
cy.server();
cy.route("/api/some/REST/endpoint", { response: [1,2,3] });
cy.visit("#/my-page");
cy.findByText("Something").should("be.visible");
});
});
// home-page.spec.js
describe("Home page", () => {
it("for logged-in user", () => {
cy.login("admin")
cy.vistit("/home")
cy.matchImageSnapshot() // "Home page for logged-in user.png"
cy.matchImageSnapshot(name);
cy.matchImageSnapshot(options);
cy.matchImageSnapshot(name, options);
})
})
Baseline
Current snapshot
Diff
v.X
v.Y
for cloud service
⚡️ quick setup - 😢
💰cheap - 😢
🚀 solid - 😢
~21 online services
percy agent
cy.percySnapshot();
cypress runner
Visual rendering & testing infrastructure
percy builds
DOM + assets (SHA256)
// home-page.spec.js
describe("Home page", () => {
it("for logged-in user", () => {
cy.login("admin")
cy.vistit("/home")
cy.percySnapshot() // "Home page for logged-in user.png"
cy.percySnapshot(name);
cy.percySnapshot(options);
cy.percySnapshot("Homepage responsive test", { widths: [768, 992, 1200] });
})
})
local comparison
cloud comparison
Cypress.Commands.add("vrt", (...args) => {
let name;
let options;
if (typeof args[0] === "object") {
options = args[0];
} else {
[name, options] = args;
}
// Set the proper viewport height for local vrt when minHeight-percy option is set
if (options && options.minHeight) {
const PERCY_MAX_HEIGHT = 2000;
if (options.minHeight > PERCY_MAX_HEIGHT) {
throw new Error(
`Your minHeight ${options.minHeight} is greater than
PERCY_MAX_HEIGHT=${PERCY_MAX_HEIGHT}`,
);
}
cy.viewport(Cypress.config("viewportWidth"), options.minHeight);
}
if (Cypress.env("percy")) {
cy.percySnapshot(name, options);
} else {
cy.matchImageSnapshot(name, options);
}
});
percy exec -- cypress run --env percy=true
👩💻
generate baseline
snapshots
local comparison
Merge Request
label: vrt
🏁
6am
branch: develop
255 snapshots
~ 15min (including app build)
(window size)
import Highcharts from "highcharts";
Highcharts.setOptions({
chart: {
animation: false,
},
plotOptions: {
series: {
animation: false,
},
},
});
//webpack.config
{
...,
entry: [
"core-js/stable",
"regenerator-runtime/runtime",
"custom-event-polyfill",
"isomorphic-fetch",
target === "test" && "./src/main/javascript/uiTestEntry.js",
"./src/main/javascript/main.js",
].filter(Boolean),
}
// setTimeout, setInterval etc. ...
cy.clock(Date.UTC(2020, 1, 11));
// only Date
cy.clock(Date.UTC(2020, 1, 11), ["Date"]);
cy.route("/api/something").as("APICall");
cy.wait("@APICall");
cy.doSnapshot();
cy.route("/api/something").as("APICall");
cy.findByText("Text to wait for");
// or
cy.getByTestId("spinner").should("not.be.visible");
cy.doSnapshot();
cy.get('footer').scrollIntoView()
Pages that: