Last active
October 13, 2022 15:25
-
-
Save stoefln/7b284533677c903586c919f9eefbeed8 to your computer and use it in GitHub Desktop.
configure testRunner to rename screenshots
This file contains 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
// after each test run, insert ".assertion" into the filename of screenshots which have been taken during an "Assertion" AKA "Check content" step | |
// this way all screenshots EXCEPT assertion screenshots could be ignored with .gitignore directive: | |
// *screenshot.jpg | |
// !*screenshot.assertion.jpg | |
const renameScreenshots = function(testRun){ | |
testRun.stepResults.forEach((sr) => { | |
if (sr.step.isAssertionStep) { | |
const screenshotPath = testRun.getScreenshotPathByStepId(sr.step.id) | |
const newFilenpath = screenshotPath.replace(".jpg", ".assertion.jpg") | |
const newFilename = path.basename(newFilenpath) | |
fs.renameSync(screenshotPath, newFilenpath) | |
sr.setScreenshot(newFilename) | |
} | |
}) | |
} | |
batchRunner.addOnTestFail('config', (test, testRun, stepResult) => { | |
renameScreenshots(testRun) | |
}) | |
batchRunner.addOnTestSuccess("config", (test, testRun) => { | |
renameScreenshots(testRun) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment