Skip to content

Commit

Permalink
Merge branch 'master' into features/parallel-execution
Browse files Browse the repository at this point in the history
* master:
  fixed a problem with showing redundant output summary
  fixed a problem with the logger
  updated sample nightwatch.json
  small refactoring to make it more consistent with the rest of assertions
  Corrected errors in the tests for urlContains and urlEquals
  Update testUrlEquals.js
  Create testUrlContains.js
  Create testUrlEquals.js
  Create urlContains.js
  Add urlEquals assertion
  refactor: reduce function calls for logTimestamp
  chore: rename logTimestap to logTimestamp
  style: break some overlong lines
  style: satisfy jshint indention warnings
  • Loading branch information
beatfactor committed May 25, 2014
2 parents 4bc9874 + 957ba27 commit 565627d
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 19 deletions.
20 changes: 16 additions & 4 deletions bin/nightwatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
"custom_commands_path" : "./examples/custom-commands",
"custom_assertions_path" : "",
"globals_path" : "./examples/globals.json",
"live_output" : false,

"selenium" : {
"start_process" : false,
"server_path" : "",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : "",
"webdriver.firefox.profile" : ""
}
},

"test_settings" : {
Expand All @@ -20,9 +26,6 @@
"selenium_port" : 4444,
"silent" : true,
"disable_colors": false,
"firefox_profile" : false,
"chrome_driver" : "",
"ie_driver" : "",
"screenshots" : {
"enabled" : false,
"path" : ""
Expand Down Expand Up @@ -58,6 +61,15 @@
}
},

"phantomjs" : {
"desiredCapabilities" : {
"browserName" : "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : true,
"phantomjs.binary.path" : "/path/to/phantomjs"
}
},

"browserstack" : {
"selenium" : {
"start_process" : false
Expand Down
4 changes: 2 additions & 2 deletions lib/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ module.exports = new (function() {
globalResults.failed += results.failed;
globalResults.errors += results.errors;
globalResults.skipped += results.skipped;
globalResults.tests += results.tests;
globalResults.tests += results.tests.length;

if (opts.output && (opts.modulesNo > 1 || testResults.tests != globalResults.tests || testResults.steps.length > 1)) {
if (opts.output && (opts.modulesNo > 1 || testResults.tests !== globalResults.tests || testResults.steps.length > 1)) {
client.printResult(startTime);
}

Expand Down
35 changes: 35 additions & 0 deletions lib/selenium/assertions/urlContains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Checks if the current URL contains the given value.
*
* ```
* this.demoTest = function (client) {
* browser.assert.urlContains('google');
* };
* ```
*
* @method urlContains
* @param {string} expected The value expected to exist within the current URL.
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
* @api assertions
*/

var util = require('util');
exports.assertion = function(expected, msg) {

this.message = msg || util.format('Testing if the URL contains "%s".', expected);
this.expected = expected;

this.pass = function(value) {
return value.indexOf(this.expected) > -1;
};

this.value = function(result) {
return result.value;
};

this.command = function(callback) {
this.api.url(callback);
return this;
};

};
35 changes: 35 additions & 0 deletions lib/selenium/assertions/urlEquals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Checks if the current url equals the given value.
*
* ```
* this.demoTest = function (client) {
* browser.assert.urlEquals('http://www.google.com');
* };
* ```
*
* @method urlEquals
* @param {string} expected The expected url.
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default.
* @api assertions
*/

var util = require('util');
exports.assertion = function(expected, msg) {

this.message = msg || util.format('Testing if the URL equals "%s".', expected);
this.expected = expected;

this.pass = function(value) {
return value === this.expected;
};

this.value = function(result) {
return result.value;
};

this.command = function(callback) {
this.api.url(callback);
return this;
};

};
31 changes: 18 additions & 13 deletions lib/util/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function logObject(obj) {
console.log(util.inspect(obj, false, 3, true));
}

function logTimestap() {
function logTimestamp() {
if (Settings.log_timestamp) {
return colors.white(timestamp()) + ' ';
}
Expand All @@ -105,19 +105,24 @@ function logMessage(type, message, args) {
}

var messageStr = '';
var timestamp = logTimestamp();
switch (type) {
case 'ERROR':
messageStr = colors.yellow(type, colors.background.dark_gray) + ' ' + logTimestap() + colors.light_green(message);
break;
case 'INFO':
messageStr = colors.light_purple(type, colors.background.black) + ' ' + logTimestap() + colors.light_cyan(message);
break;
case 'LOG':
messageStr = colors.white(type+' ', colors.background.black) + ' ' + logTimestap() + colors.white(message);
break;
case 'WARN':
messageStr = colors.light_green(type, colors.background.black) + ' ' + logTimestap() + colors.light_green(message);
break;
case 'ERROR':
messageStr = colors.yellow(type, colors.background.dark_gray) +' '+
timestamp + colors.light_green(message);
break;
case 'INFO':
messageStr = colors.light_purple(type, colors.background.black) +' '+
timestamp + colors.light_cyan(message);
break;
case 'LOG':
messageStr = colors.white(type+' ', colors.background.black) +' '+
timestamp + colors.white(message);
break;
case 'WARN':
messageStr = colors.light_green(type, colors.background.black) +' '+
timestamp + colors.light_green(message);
break;
}

process.stdout.write(messageStr);
Expand Down
64 changes: 64 additions & 0 deletions tests/src/assertions/testUrlContains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var BASE_PATH = process.env.NIGHTWATCH_COV
? 'lib-cov'
: 'lib';
var Api = require('../../../'+BASE_PATH+'/core/api.js');
module.exports = {
setUp: function (callback) {
callback();
},

'urlContains assertion passed' : function(test) {
var assertionFn = require('../../../'+BASE_PATH+'/selenium/assertions/urlContains.js');
var client = {
options : {},
api : {
url : function(callback) {
callback({
value : 'http://www.nightwatchjs.org'
});
}
},
assertion : function(passed, result, expected, msg, abortOnFailure) {
test.equals(passed, true);
test.equals(result, 'http://www.nightwatchjs.org');
test.equals(expected, 'nightwatchjs');
test.equals(msg, 'Testing if the URL contains "nightwatchjs".');
test.equals(abortOnFailure, true);
delete assertionFn;
test.done();
}
};
Api.init(client);
var m = Api.createAssertion('urlContains', assertionFn, true, client);
m._commandFn('nightwatchjs');
},

'urlContains assertion failed' : function(test) {
var assertionFn = require('../../../'+BASE_PATH+'/selenium/assertions/urlContains.js');
var client = {
options : {},
api : {
url : function(callback) {
callback({
value : 'http://www.nightwatchjs.org'
});
}
},
assertion : function(passed, result, expected, msg, abortOnFailure) {
test.equals(passed, false);
test.equals(result, 'http://www.nightwatchjs.org');
test.equals(expected, 'google');
test.equals(abortOnFailure, true);
delete assertionFn;
test.done();
}
};
Api.init(client);
var m = Api.createAssertion('urlContains', assertionFn, true, client);
m._commandFn('google');
},

tearDown : function(callback) {
callback();
}
}
64 changes: 64 additions & 0 deletions tests/src/assertions/testUrlEquals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var BASE_PATH = process.env.NIGHTWATCH_COV
? 'lib-cov'
: 'lib';
var Api = require('../../../'+BASE_PATH+'/core/api.js');
module.exports = {
setUp: function (callback) {
callback();
},

'urlEquals assertion passed' : function(test) {
var assertionFn = require('../../../'+BASE_PATH+'/selenium/assertions/urlEquals.js');
var client = {
options : {},
api : {
url : function(callback) {
callback({
value : 'http://www.nightwatchjs.org'
});
}
},
assertion : function(passed, result, expected, msg, abortOnFailure) {
test.equals(passed, true);
test.equals(result, 'http://www.nightwatchjs.org');
test.equals(expected, 'http://www.nightwatchjs.org');
test.equals(msg, 'Testing if the URL equals "http://www.nightwatchjs.org".');
test.equals(abortOnFailure, true);
delete assertionFn;
test.done();
}
};
Api.init(client);
var m = Api.createAssertion('urlEquals', assertionFn, true, client);
m._commandFn('http://www.nightwatchjs.org');
},

'urlEquals assertion failed' : function(test) {
var assertionFn = require('../../../'+BASE_PATH+'/selenium/assertions/title.js');
var client = {
options : {},
api : {
title : function(callback) {
callback({
value : 'http://www.nightwatchjs.org'
});
}
},
assertion : function(passed, result, expected, msg, abortOnFailure) {
test.equals(passed, false);
test.equals(result, 'http://www.nightwatchjs.org');
test.equals(expected, 'http://www.google.com');
test.equals(abortOnFailure, true);
delete assertionFn;
test.done();
}
};
Api.init(client);
var m = Api.createAssertion('urlEquals', assertionFn, true, client);
m._commandFn('http://www.google.com');
},

tearDown : function(callback) {
callback();
}
}

0 comments on commit 565627d

Please sign in to comment.