Created
June 21, 2015 15:43
-
-
Save willmendesneto/795842b996a2d9e3e1f6 to your computer and use it in GitHub Desktop.
Protractor snapshot UI tests configuration using Jasmine
This file contains hidden or 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
'use strict'; | |
var ScreenshotReporter = require('./screenshots.js'); | |
var path = require('path'); | |
exports.config = { | |
seleniumAddress: 'http://0.0.0.0:4444/wd/hub', | |
// Do not start a Selenium Standalone sever - only run this using chrome. | |
chromeOnly: true, | |
chromeDriver: '../../node_modules/protractor/selenium/chromedriver', | |
baseUrl: '', | |
directConnect: false, | |
specs: ['./**/*Spec.js'], | |
jasmineNodeOpts: { | |
// If set, only execute specs whose names match the pattern, which is | |
// internally compiled to a RegExp. | |
grep: 'pattern', | |
// Inverts 'grep' matches | |
invertGrep: false, | |
// If true, display spec names. | |
isVerbose: true, | |
showTiming: true, | |
// If true, print colors to the terminal. | |
showColors: true, | |
// If true, include stack traces in failures. | |
includeStackTrace: true, | |
// Default time to wait in ms before a test fails. | |
defaultTimeoutInterval: 30000 | |
}, | |
onPrepare: function(){ | |
browser.ignoreSynchronization = true; | |
global.bd = browser.driver; | |
jasmine.getEnv().addReporter(new ScreenshotReporter( | |
path.join(process.cwd(), './screenshots'))); | |
}, | |
// Framework to use. Jasmine 2 is recommended. | |
framework: 'jasmine', | |
// Capabilities to be passed to the webdriver instance. | |
capabilities: { | |
browserName: 'chrome', | |
chromeOptions: { | |
args: ['--test-type'] | |
} | |
} | |
}; |
This file contains hidden or 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
var mkdirp = require('mkdirp'); | |
var fs = require('fs'); | |
var path = require('path'); | |
var ScreenshotReporter = function(dir_) { | |
var dir = (dir_ ? dir_ : '/tmp/protractorss/'); | |
dir = path.join(dir, new Date().toISOString()); | |
var index = 0; | |
// base function to take a screenshot -- change path as needed | |
var screenshot = function(testDescription, id, screenshotType) { | |
screenshotType = !!screenshotType ? 'pass' : 'failed'; | |
var fname = testDescription.replace(/\s/g, '-') + '-' + id + '-' + screenshotType + '.png'; | |
mkdirp(dir); | |
browser.takeScreenshot().then(function(png) { | |
var stream = fs.createWriteStream(path.join(dir, fname)); | |
stream.write(new Buffer(png, 'base64')); | |
stream.end(); | |
}); | |
} | |
// takes screenshot on each failed expect | |
var originalAddMatcherResult = jasmine.Spec.prototype.addMatcherResult; | |
jasmine.Spec.prototype.addMatcherResult = function() { | |
++index; | |
screenshot(this.description, index, arguments[0].passed()); | |
return originalAddMatcherResult.apply(this, arguments); | |
}; | |
// takes screenshot on each failed spec (including timeout) | |
this.reportSpecResults = function(spec) { | |
screenshot(spec.description, 'end', spec.results().passed()); | |
index = 0; | |
}; | |
}; | |
module.exports = ScreenshotReporter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment