Skip to content

Instantly share code, notes, and snippets.

@jsfez
Created October 5, 2023 20:28
Show Gist options
  • Save jsfez/f066584ea42c039a1f1dd8d926977b89 to your computer and use it in GitHub Desktop.
Save jsfez/f066584ea42c039a1f1dd8d926977b89 to your computer and use it in GitHub Desktop.
Adding argosScreenshotForResolutions command to cypress
// file: cypress/support/e2e.js
import "@argos-ci/cypress/support";
const resolutions = ["iphone-6", "ipad-2", [1024, 768]];
Cypress.Commands.add("argosScreenshotForResolutions", (name, options = {}) => {
// Save the initial viewport size
const initialViewportWidth = Cypress.config("viewportWidth");
const initialViewportHeight = Cypress.config("viewportHeight");
// Loop through the resolutions and take a screenshot for each.
resolutions.forEach((resolution) => {
let resolutionPrefix;
if (Array.isArray(resolution)) {
const [width, height] = resolution;
cy.viewport(width, height);
resolutionPrefix = `${width}x${height}`;
} else {
cy.viewport(resolution);
resolutionPrefix = resolution.toString();
}
cy.argosScreenshot(`[${resolutionPrefix}] ${name}`, options);
});
// Reset the viewport back to its initial size.
cy.viewport(initialViewportWidth, initialViewportHeight);
});
// Example usage:
// # cy.argosScreenshot("homepage") 👈 Replace this
// argosScreenshotForResolutions(resolutions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment