Skip to content

Commit

Permalink
Added screenshots on_error option
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Jun 30, 2015
1 parent ab9b122 commit 0aeaf42
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Nightwatch.prototype.setOptions = function(options) {
if (typeof screenshots.path == 'undefined') {
throw new Error('Please specify the screenshots.path in nightwatch.json.');
}
this.options.screenshots.on_error = this.options.screenshots.on_error ||
(typeof this.options.screenshots.on_error == 'undefined');
this.api.screenshotsPath = this.api.options.screenshotsPath = screenshots.path;
} else {
this.options.screenshots = {
Expand Down Expand Up @@ -333,7 +335,7 @@ Nightwatch.prototype.runProtocolAction = function(requestOptions, callback) {
})
.on('error', function(result, response, screenshotContent) {
result = self.handleTestError(result);
if (screenshotContent && self.options.screenshots.enabled) {
if (screenshotContent && self.options.screenshots.on_error) {
var fileNamePath = Utils.getScreenshotFileName('ERROR_', self.options.screenshots.path);
self.saveScreenshotToFile(fileNamePath, screenshotContent);
result.lastScreenshotFile = fileNamePath;
Expand Down
6 changes: 4 additions & 2 deletions lib/runner/cli/clirunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ CliRunner.prototype = {

if (typeof this.test_settings.test_workers != 'undefined') {
this.settings.test_workers = this.test_settings.test_workers;
} else if (typeof this.settings.test_workers != 'undefined') {
this.test_settings.test_workers = this.settings.test_workers;
}

if (typeof this.argv.skipgroup == 'string') {
Expand Down Expand Up @@ -576,7 +578,6 @@ CliRunner.prototype = {

this.startSelenium(function() {
self.startChildProcesses(envs, function(code) {

self.stopSelenium().then(function() {
if (self.parallelModeWorkers()) {
return self.runGlobalAfter();
Expand Down Expand Up @@ -697,10 +698,11 @@ CliRunner.prototype = {

self.childProcessOutput[filename] = [];

var childArgs = args.slice();
var childArgs = [];
childArgs.push('--test', modulePath, '--test-worker');
var child = new ChildProcess(filename, index, self.childProcessOutput[filename], self.settings, childArgs);
child.setLabel(Utils.getModuleKey(modulePath, self.settings.src_folders, modulePaths));

self.runningProcesses[child.itemKey] = child;
self.runningProcesses[child.itemKey].run(availColors, function (output, exitCode) {
if (exitCode > 0) {
Expand Down
18 changes: 18 additions & 0 deletions tests/src/index/testNightwatchIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ module.exports = {
eq(client.api.launch_url, '/home');

eq(client.options.screenshots.enabled, false);
eq(typeof client.options.screenshots.on_error, 'undefined');
eq(client.api.options.screenshots, false);
test.done();
},
Expand Down Expand Up @@ -200,11 +201,28 @@ module.exports = {
var eq = test.equals;

eq(client.api.options.log_screenshot_data, true);
eq(client.options.screenshots.on_error, true);
eq(client.api.options.screenshotsPath, '');

test.done();
},

testSetOptionsScreenshotsOnError : function(test) {
var client = this.client = Client.init({
screenshots : {
enabled : true,
on_error : true,
path : ''
},
log_screenshot_data : true
});
var eq = test.equals;

eq(client.options.screenshots.on_error, true);

test.done();
},

testSetOptionsScreenshotsThrows : function(test) {
test.throws(function() {
this.client = Client.init({
Expand Down
4 changes: 4 additions & 0 deletions tests/src/runner/testParallelExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ module.exports = {
enabled : true,
workers : 'auto'
});
test.deepEqual(runner.test_settings.test_workers, {
enabled : true,
workers : 'auto'
});
test.ok(runner.parallelModeWorkers());

},
Expand Down

0 comments on commit 0aeaf42

Please sign in to comment.