New 'screenshot' option when launching a test

This commit is contained in:
Gaël Métais
2015-02-05 15:25:17 +01:00
parent 5bbe4cde77
commit ae47333eef
9 changed files with 418 additions and 73 deletions
+31 -9
View File
@@ -9,24 +9,28 @@ function ResultsDatastore() {
'use strict';
var resultFileName = 'results.json';
var resultScreenshotName = 'screenshot.jpg';
var resultsFolderName = 'results';
var resultsDir = path.join(__dirname, '..', '..', '..', resultsFolderName);
this.saveResult = function(testResults) {
var promise = createResultFolder(testResults.runId);
return createResultFolder(testResults.runId)
debug('Saving results to disk...');
.then(function() {
return saveScreenshotIfExists(testResults);
})
promise.then(function() {
.then(function() {
var resultFilePath = path.join(resultsDir, testResults.runId, resultFileName);
debug('Destination file is %s', resultFilePath);
return Q.nfcall(fs.writeFile, resultFilePath, JSON.stringify(testResults, null, 2));
});
debug('Saving results to disk...');
return promise;
var resultFilePath = path.join(resultsDir, testResults.runId, resultFileName);
debug('Destination file is %s', resultFilePath);
return Q.nfcall(fs.writeFile, resultFilePath, JSON.stringify(testResults, null, 2));
});
};
@@ -84,6 +88,24 @@ function ResultsDatastore() {
return deferred.promise;
}
// If there is a screenshot, save it as screenshot.jpg in the same folder as the results
function saveScreenshotIfExists(testResults) {
var deferred = Q.defer();
if (testResults.screenshotBuffer) {
var screenshotFilePath = path.join(resultsDir, testResults.runId, resultScreenshotName);
fs.writeFile(screenshotFilePath, testResults.screenshotBuffer);
delete testResults.screenshotBuffer;
} else {
deferred.resolve();
}
return deferred;
}
}
module.exports = ResultsDatastore;
+3
View File
@@ -1,4 +1,5 @@
var Q = require('q');
var debug = require('debug')('ylt:runsQueue');
function RunsQueue() {
@@ -11,6 +12,8 @@ function RunsQueue() {
var deferred = Q.defer();
var startingPosition = queue.length;
debug('Adding run %s to the queue, position is %d', runId, startingPosition);
if (startingPosition === 0) {
// The queue is empty, let's run immediatly