diff --git a/bin/nightwatch.json b/bin/nightwatch.json index b5dcc5411e..b5be08a7c6 100644 --- a/bin/nightwatch.json +++ b/bin/nightwatch.json @@ -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" : { @@ -20,9 +26,6 @@ "selenium_port" : 4444, "silent" : true, "disable_colors": false, - "firefox_profile" : false, - "chrome_driver" : "", - "ie_driver" : "", "screenshots" : { "enabled" : false, "path" : "" @@ -58,6 +61,15 @@ } }, + "phantomjs" : { + "desiredCapabilities" : { + "browserName" : "phantomjs", + "javascriptEnabled" : true, + "acceptSslCerts" : true, + "phantomjs.binary.path" : "/path/to/phantomjs" + } + }, + "browserstack" : { "selenium" : { "start_process" : false diff --git a/lib/runner/run.js b/lib/runner/run.js index 2c75e463a5..8509d6913f 100644 --- a/lib/runner/run.js +++ b/lib/runner/run.js @@ -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); } diff --git a/lib/selenium/assertions/urlContains.js b/lib/selenium/assertions/urlContains.js new file mode 100644 index 0000000000..47898cb31f --- /dev/null +++ b/lib/selenium/assertions/urlContains.js @@ -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; + }; + +}; diff --git a/lib/selenium/assertions/urlEquals.js b/lib/selenium/assertions/urlEquals.js new file mode 100644 index 0000000000..c91d0beb09 --- /dev/null +++ b/lib/selenium/assertions/urlEquals.js @@ -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; + }; + +}; diff --git a/lib/util/logger.js b/lib/util/logger.js index 99f81e3873..61bcff7a95 100644 --- a/lib/util/logger.js +++ b/lib/util/logger.js @@ -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()) + ' '; } @@ -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); diff --git a/tests/src/assertions/testUrlContains.js b/tests/src/assertions/testUrlContains.js new file mode 100644 index 0000000000..b870f1e417 --- /dev/null +++ b/tests/src/assertions/testUrlContains.js @@ -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(); + } +} diff --git a/tests/src/assertions/testUrlEquals.js b/tests/src/assertions/testUrlEquals.js new file mode 100644 index 0000000000..90d99b21e5 --- /dev/null +++ b/tests/src/assertions/testUrlEquals.js @@ -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(); + } +}