Created
October 5, 2023 20:28
-
-
Save jsfez/f066584ea42c039a1f1dd8d926977b89 to your computer and use it in GitHub Desktop.
Adding argosScreenshotForResolutions command to cypress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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