protractor-jasmine2-screenshot-reporter
Advanced tools
Comparing version 0.0.5 to 0.1.0
43
index.js
@@ -28,2 +28,15 @@ var fs = require('fs'), | ||
var writeMetadata = function(data, filename) { | ||
var stream; | ||
try { | ||
stream = fs.createWriteStream(filename); | ||
stream.write(JSON.stringify(data, null, '\t')); | ||
stream.end(); | ||
} catch(e) { | ||
console.error('Couldn\'t save metadata: ' + filename); | ||
} | ||
}; | ||
// returns suite clone or creates one | ||
@@ -54,2 +67,6 @@ var getSuiteClone = function(suite) { | ||
var metadataBuilder = function(spec, suites, capabilities) { | ||
return false; | ||
}; | ||
// TODO: more options | ||
@@ -62,2 +79,3 @@ opts = opts || {}; | ||
opts.pathBuilder = opts.pathBuilder || pathBuilder; | ||
opts.metadataBuilder = opts.metadataBuilder || metadataBuilder; | ||
@@ -127,8 +145,25 @@ | ||
browser.getCapabilities().then(function (capabilities) { | ||
spec.filename = opts.pathBuilder(spec, suites, capabilities) + '.png'; | ||
var fullpath = path.join(opts.dest, spec.filename); | ||
var screenshotPath, | ||
metadataPath, | ||
metadata, | ||
file; | ||
mkdirp(path.dirname(fullpath), function(err) { | ||
file = opts.pathBuilder(spec, suites, capabilities); | ||
spec.filename = file + '.png'; | ||
screenshotPath = path.join(opts.dest, spec.filename); | ||
metadata = opts.metadataBuilder(spec, suites, capabilities); | ||
if (metadata) { | ||
metadataPath = path.join(opts.dest, file + '.json'); | ||
mkdirp(path.dirname(metadataPath), function(err) { | ||
if(err) { | ||
throw new Error('Could not create directory for ' + metadataPath); | ||
} | ||
writeMetadata(metadata, metadataPath); | ||
}); | ||
} | ||
mkdirp(path.dirname(screenshotPath), function(err) { | ||
if(err) { | ||
throw new Error('Could not create directory for ' + fullpath); | ||
throw new Error('Could not create directory for ' + screenshotPath); | ||
} | ||
@@ -135,0 +170,0 @@ writeScreenshot(png, spec.filename); |
{ | ||
"name": "protractor-jasmine2-screenshot-reporter", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "Use the screenshot reporter to capture screenshots after each executed Protractor test case.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -82,1 +82,14 @@ ## Protractor screenshot reporter for Jasmine2 | ||
By default, the path builder will generate a random ID for each spec. | ||
### Metadata Builder (optional) | ||
Function used to build custom metadata objects for each spec. Files (json) will use the same filename and path as created by Path Builder. | ||
For example: | ||
<pre><code>jasmine.getEnv().addReporter(new ScreenShotReporter({ | ||
metadataBuilder: function(currentSpec, suites, browserCapabilities) { | ||
return { id: spec.id, os: browserCapabilities.browserName }; | ||
} | ||
}));</code></pre> | ||
By default, the runner builder will not save any metadata except the actual html report. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10921
167
95