diff --git a/README.md b/README.md index 360ba57d..29e37e45 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,9 @@ cy.matchImage({ // helps with screenshots being scaled 2x on high-density screens like Mac Retina // default: true forceDeviceScaleFactor: false, + // title used for naming the image file + // default: Cypress.currentTest.titlePath (your test title) + title: `${Cypress.currentTest.titlePath.join(' ')} (${Cypress.browser.displayName})` }) ``` diff --git a/src/commands.ts b/src/commands.ts index 8ab7175f..1ffa4609 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -10,6 +10,7 @@ declare global { updateImages?: boolean; imagesDir?: string; maxDiffThreshold?: number; + title?: string; }; interface Chainable { @@ -30,7 +31,7 @@ Cypress.Commands.add( { prevSubject: "optional" }, (subject, options = {}) => { const $el = subject as JQuery | undefined; - let title = Cypress.currentTest.titlePath.join(" "); + let title = options.title || Cypress.currentTest.titlePath.join(" "); if (typeof nameCacheCounter[title] === "undefined") nameCacheCounter[title] = -1; title += ` #${++nameCacheCounter[title]}`;