diff --git a/README.md b/README.md index 90c2cca..90183d9 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,18 @@ new ScreenShotReporter({ Default is `false`. +### Screenshots only for failed test cases (optional) +Also you can define if you want capture screenshots only from failed test cases using the `takeScreenShotsOnlyForFailedSpecs:` option: + +```javascript +new ScreenShotReporter({ + baseDirectory: '/tmp/screenshots' + , takeScreenShotsOnlyForFailedSpecs: true +}); +``` + +Default is `false`. + ## Postprocess Meta Data A screenshot is saved as PNG image. Along with it, a JSON file with a matching filename is created. diff --git a/index.js b/index.js index 8cc5811..2ae21b0 100644 --- a/index.js +++ b/index.js @@ -96,6 +96,8 @@ function ScreenshotReporter(options) { this.metaDataBuilder = options.metaDataBuilder || defaultMetaDataBuilder; this.takeScreenShotsForSkippedSpecs = options.takeScreenShotsForSkippedSpecs || false; + this.takeScreenShotsOnlyForFailedSpecs = + options.takeScreenShotsOnlyForFailedSpecs || false; } /** Function: reportSpecResults @@ -114,6 +116,9 @@ function reportSpecResults(spec) { if(!self.takeScreenShotsForSkippedSpecs && results.skipped) { return; } + if(self.takeScreenShotsOnlyForFailedSpecs && results.passed()) { + return; + } browser.takeScreenshot().then(function (png) { browser.getCapabilities().then(function (capabilities) { @@ -160,4 +165,4 @@ function reportSpecResults(spec) { }; -module.exports = ScreenshotReporter; \ No newline at end of file +module.exports = ScreenshotReporter;