Skip to content

Instantly share code, notes, and snippets.

@stoefln
Last active October 13, 2022 15:25
Show Gist options
  • Save stoefln/7b284533677c903586c919f9eefbeed8 to your computer and use it in GitHub Desktop.
Save stoefln/7b284533677c903586c919f9eefbeed8 to your computer and use it in GitHub Desktop.
configure testRunner to rename screenshots
// 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