Skip to content

Commit

Permalink
Merge branch 'gh-65' of https://github.com/sethmcl/nightwatch into se…
Browse files Browse the repository at this point in the history
…thmcl-gh-65
  • Loading branch information
beatfactor committed Jun 24, 2014
2 parents 2f934d2 + 05ea572 commit 536d461
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var util = require('util');
var fs = require('fs');
var path = require('path');
var events = require('events');
var mkpath = require('mkpath');
var HttpRequest = require('./http/request.js');
var CommandQueue = require('./core/queue.js');
var Assertion = require('./core/assertion.js');
Expand Down Expand Up @@ -326,11 +327,27 @@ Nightwatch.prototype.enqueueCommand = function(commandName, args, callback) {
return this.queue.run();
};

Nightwatch.prototype.saveScreenshotToFile = function(fileName, content) {
fs.writeFile(fileName, content, 'base64', function(err) {
Nightwatch.prototype.saveScreenshotToFile = function(fileName, content, cb) {
cb = cb || function() {};

var dir = path.resolve(fileName, '..');
var fail = function (err) {
console.log(Logger.colors.yellow('Couldn\'t save screenshot to '), fileName);
Logger.warn(err);
cb(err);
};

mkpath(dir, function (err) {
if (err) {
console.log(Logger.colors.yellow('Couldn\'t save screenshot to '), fileName);
Logger.warn(err);
fail(err);
} else {
fs.writeFile(fileName, content, 'base64', function(err) {
if (err) {
fail(err);
} else {
cb(null, fileName);
}
});
}
});
};
Expand Down
20 changes: 20 additions & 0 deletions tests/src/index/testNightwatchIndex.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var os = require('os');
var path = require('path');
var fs = require('fs');
var Client = require('../../nightwatch.js');

module.exports = {
Expand Down Expand Up @@ -83,6 +86,23 @@ module.exports = {
});
},

'Test saveScreenshotToFile' : function(test) {
var client = this.client = Client.init();
var tmp = os.tmpdir();
var filePath = path.resolve(tmp, 'r3lekb', 'foo.png');
var data = 'nightwatch';

client.saveScreenshotToFile(filePath, data, function(err, actualFilePath) {
test.equal(err, null);
test.equal(actualFilePath, filePath);

fs.readFile(actualFilePath, function(err) {
test.equal(err, null);
test.done();
});
});
},

tearDown : function(callback) {
this.client.queue.reset();
this.client = null;
Expand Down

0 comments on commit 536d461

Please sign in to comment.