nightwatch
Advanced tools
Comparing version 0.2.2 to 0.2.4
@@ -1,83 +0,162 @@ | ||
var fs = require('fs'), path = require('path'); | ||
var Logger = require('../lib/logger.js'); | ||
/** | ||
* Module dependencies | ||
*/ | ||
var fs = require('fs'), | ||
path = require('path'), | ||
Logger = require('../lib/logger.js'), | ||
cli = require('./_cli.js'); | ||
// CLI definitions | ||
// $ nightwatch -c | ||
// $ nightwatch --config | ||
cli.command('config') | ||
.demand(true) | ||
.description('Path to configuration file') | ||
.alias('c') | ||
.defaults('./settings.json'); | ||
// $ nightwatch -o | ||
// $ nightwatch --output | ||
cli.command('output') | ||
.description('Where to save the JUnit XML test reports.') | ||
.alias('o') | ||
.defaults('tests_output'); | ||
// $ nightwatch -e | ||
// $ nightwatch --env saucelabs | ||
cli.command('env') | ||
.description('Testing environment to use.') | ||
.alias('e') | ||
.defaults('default'); | ||
// $ nightwatch -v | ||
// $ nightwatch --verbose | ||
cli.command('verbose') | ||
.description('Turns on selenium command logging during the session.') | ||
.alias('v'); | ||
// $ nightwatch -t | ||
// $ nightwatch --test | ||
cli.command('test') | ||
.description('Runs a single test.') | ||
.alias('t'); | ||
// $ nightwatch -g | ||
// $ nightwatch --group | ||
cli.command('group') | ||
.description('Runs a group of tests (i.e. a folder)') | ||
.alias('g'); | ||
// $ nightwatch -s | ||
// $ nightwatch --skipgroup | ||
cli.command('skipgroup') | ||
.description('Skips one or several (comma separated) group of tests.') | ||
.alias('s'); | ||
// $ nightwatch -s | ||
// $ nightwatch --skipgroup | ||
cli.command('help') | ||
.description('Shows this help.') | ||
.alias('h'); | ||
/** | ||
* Looks for pattern ${VAR_NAME} in settings | ||
* @param {Object} target | ||
*/ | ||
function replaceEnvVariables(target) { | ||
for (var key in target) { | ||
switch(typeof target[key]) { | ||
case 'object': | ||
replaceEnvVariables(target[key]); | ||
break; | ||
case 'string': | ||
target[key] = target[key].replace(/\$\{(\w+)\}/g, function(match, varName) { | ||
return process.env[varName] || '${' + varName + '}'; | ||
}); | ||
break; | ||
} | ||
} | ||
} | ||
/** | ||
* Read the provided config json file; defaults to settings.json if one isn't provided | ||
* @param {Object} argv | ||
*/ | ||
function readSettings(argv) { | ||
var settings; | ||
// use default settings.json file if we haven't received another value | ||
if (cli.command('config').isDefault(argv.c)) { | ||
var defaultValue = cli.command('config').defaults(); | ||
if (fs.existsSync(cli.command('config').defaults())) { | ||
argv.c = path.join(path.resolve('./'), argv.c); | ||
} else { | ||
argv.c = path.join(__dirname, argv.c); | ||
} | ||
} | ||
// reading the settings file | ||
try { | ||
settings = require(argv.c); | ||
replaceEnvVariables(settings); | ||
} catch (ex) { | ||
settings = {}; | ||
} | ||
return settings; | ||
}; | ||
/** | ||
* | ||
* @param {Object} argv | ||
*/ | ||
function parseTestSettings(argv) { | ||
// checking if the env passed is valid | ||
if (!settings.test_settings) { | ||
throw new Error('No testing environment specified.'); | ||
} | ||
if (!(argv.e in settings.test_settings)) { | ||
throw new Error('Invalid testing environment specified: ' + argv.e); | ||
} | ||
// picking the environment specific test settings | ||
var test_settings = settings.test_settings[argv.e]; | ||
test_settings.custom_commands_path = settings.custom_commands_path || ''; | ||
if (argv.v) { | ||
test_settings.silent = false; | ||
} | ||
if (typeof argv.s == 'string') { | ||
test_settings.skipgroup = argv.s.split(','); | ||
} | ||
return test_settings; | ||
} | ||
try { | ||
var DEFAULTS = { | ||
config : { | ||
demand : true, | ||
alias : 'c', | ||
description : 'Path to configuration file', | ||
default: './settings.json' | ||
}, | ||
output : { | ||
alias : 'o', | ||
description : 'Where to save the junit xml test reports.', | ||
default : 'tests_output' | ||
}, | ||
env : { | ||
alias : 'e', | ||
description : 'Testing environment to use', | ||
default: 'default' | ||
}, | ||
verbose : { | ||
alias : 'v', | ||
description : 'Turns on selenium command logging during the session' | ||
}, | ||
test : { | ||
alias : 't', | ||
description : 'Run a single test' | ||
}, | ||
group : { | ||
alias : 'g', | ||
description : 'Run a single group of tests (a folder)' | ||
}, | ||
skipgroup : { | ||
alias : 's', | ||
description : 'Skip one or several (comma separated) group of tests' | ||
}, | ||
help : { | ||
alias : 'h', | ||
description : 'Shows this help' | ||
} | ||
}; | ||
var argv = cli.init(); | ||
var opt = require('optimist'); | ||
var argv = opt.usage('Usage: $0 [options]') | ||
.options(DEFAULTS) | ||
.argv; | ||
if (argv.help) { | ||
opt.showHelp(); | ||
cli.showHelp(); | ||
} else { | ||
if (argv.c === DEFAULTS.config["default"]) { | ||
if (fs.existsSync('./settings.json')) { | ||
argv.c = path.join(path.resolve('./'), argv.c); | ||
} else { | ||
argv.c = path.join(__dirname, argv.c); | ||
} | ||
} | ||
process.chdir(process.cwd()); | ||
try { | ||
var settings = require(argv.c); | ||
} catch (ex) { | ||
var settings = {}; | ||
} | ||
// the selenium runner | ||
var runner = require(__dirname + '/../runner/run.js'); | ||
if (!(argv.e in settings.test_settings)) { | ||
throw new Error("Invalid testing environment specified: " + argv.e); | ||
} | ||
var output_folder; | ||
if (argv.o !== DEFAULTS.output["default"] || typeof settings.output_folder == "undefined" || | ||
settings.output_folder == "") { | ||
output_folder = argv.o; | ||
} else { | ||
output_folder = settings.output_folder; | ||
} | ||
var settings = readSettings(argv); | ||
var test_settings = settings.test_settings && settings.test_settings[argv.e] || {}; | ||
test_settings.custom_commands_path = settings.custom_commands_path; | ||
// setting the output folder | ||
var output_folder = cli.command('output').isDefault(argv.o) && | ||
settings.output_folder || argv.o; | ||
var test_settings = parseTestSettings(argv); | ||
// setting the source of the test(s) | ||
var testsource; | ||
if (typeof argv.t == 'string') { | ||
var testsource = (argv.t.indexOf(process.cwd()) === -1) ? | ||
testsource = (argv.t.indexOf(process.cwd()) === -1) ? | ||
path.join(process.cwd(), argv.t) : | ||
@@ -92,11 +171,4 @@ argv.t; | ||
} | ||
if (argv.v) { | ||
test_settings.silent = false; | ||
} | ||
if (typeof argv.s == 'string') { | ||
test_settings.skipgroup = argv.s.split(','); | ||
} | ||
// running the tests | ||
runner.startSelenium(settings, test_settings, function(error, child, error_out, exitcode) { | ||
@@ -120,5 +192,4 @@ if (error) { | ||
} catch (ex) { | ||
Logger.error('There was an error while starting the test runner:'); | ||
console.trace(); | ||
console.log(Logger.colors.red(ex.message)); | ||
Logger.error('There was an error while starting the test runner:\n'); | ||
console.log(ex.stack); | ||
} |
@@ -18,6 +18,6 @@ { | ||
"selenium_host" : "127.0.0.1", | ||
"selenium_port" : 4444, | ||
"silent": true, | ||
"output": true, | ||
"firefox_profile": false, | ||
"selenium_port" : 4444, | ||
"silent" : true, | ||
"output" : true, | ||
"firefox_profile" : false, | ||
"screenshots" : { | ||
@@ -27,6 +27,6 @@ "enabled" : false, | ||
}, | ||
"desiredCapabilities": { | ||
"browserName": "firefox", | ||
"javascriptEnabled": true, | ||
"acceptSslCerts": true | ||
"desiredCapabilities" : { | ||
"browserName" : "firefox", | ||
"javascriptEnabled" : true, | ||
"acceptSslCerts" : true | ||
} | ||
@@ -37,8 +37,8 @@ }, | ||
"selenium_host" : "ondemand.saucelabs.com", | ||
"selenium_port" : 80, | ||
"username" : "...", | ||
"access_key" : "...", | ||
"selenium_port" : 80, | ||
"username" : "${SAUCE_USERNAME}", | ||
"access_key" : "${SAUCE_ACCESS_KEY}", | ||
"use_ssl" : false, | ||
"silent": false, | ||
"output": true, | ||
"silent" : false, | ||
"output" : true, | ||
"screenshots" : { | ||
@@ -54,2 +54,4 @@ "enabled" : false, | ||
} | ||
} | ||
} | ||
@@ -19,3 +19,3 @@ /** | ||
client | ||
.url("http://www.google.com"); | ||
.url('http://google.com'); | ||
@@ -32,5 +32,11 @@ client.waitForElementVisible('body', 1000); | ||
client.url(function(result) { | ||
this.assert.ok(result.value.indexOf('google.nl') !== -1, 'Google url is ok'); | ||
}); | ||
client.assert.visible('input[type=text]') | ||
.setValue('input[type=text]', 'nightwatch') | ||
.waitForElementVisible('button[name=btnG]', 1000) | ||
.setValue('input[type=text]', '2 nightwatch') | ||
.pause(); | ||
}, | ||
@@ -37,0 +43,0 @@ |
@@ -1,15 +0,16 @@ | ||
var util = require("util"), | ||
events = require("events"), | ||
qs = require('querystring'), | ||
http = require('http'), | ||
https = require('https'), | ||
Logger = require('./logger'); | ||
var util = require('util'), | ||
events = require('events'), | ||
qs = require('querystring'), | ||
http = require('http'), | ||
https = require('https'), | ||
Logger = require('./logger'); | ||
var Settings = { | ||
selenium_host : "localhost", | ||
selenium_host : 'localhost', | ||
selenium_port : 4444, | ||
default_path : "/wd/hub", | ||
credentials : null, | ||
use_ssl : false | ||
} | ||
default_path : '/wd/hub', | ||
credentials : null, | ||
use_ssl : false | ||
} | ||
var DO_NOT_LOG_ERRORS = [ | ||
@@ -21,5 +22,5 @@ 'Unable to locate element' | ||
events.EventEmitter.call(this); | ||
this.data = options.data && JSON.stringify(options.data) || ""; | ||
this.requestOptions = this.createOptions(options); | ||
this.request = null; | ||
this.data = options.data && JSON.stringify(options.data) || ''; | ||
this.reqOptions = this.createOptions(options); | ||
this.request = null; | ||
} | ||
@@ -31,6 +32,7 @@ | ||
var reqOptions = { | ||
path : Settings.default_path + (options.path || ""), | ||
host : options.host || Settings.selenium_host, | ||
port : options.selenium_port || Settings.selenium_port, | ||
method: options.method || "POST" | ||
path : Settings.default_path + (options.path || ''), | ||
host : options.host || Settings.selenium_host, | ||
port : options.selenium_port || Settings.selenium_port, | ||
method : options.method || 'POST', | ||
headers : {} | ||
}; | ||
@@ -41,12 +43,17 @@ | ||
} | ||
reqOptions.headers = { | ||
'Content-Type': 'application/json', | ||
'Content-Length': this.data.length | ||
if (reqOptions.method.toUpperCase() === 'GET') { | ||
reqOptions.headers['Accept'] = 'application/json'; | ||
} | ||
if (this.data && this.data.length > 0) { | ||
reqOptions.headers['Content-Type'] = 'application/json'; | ||
reqOptions.headers['Content-Length'] = this.data.length; | ||
} | ||
if (Settings.credentials && | ||
Settings.credentials.username && Settings.credentials.key | ||
) { | ||
var authHeader = new Buffer(Settings.credentials.username + ":" + Settings.credentials.key).toString('base64'); | ||
reqOptions.headers['Authorization'] = "Basic " + authHeader; | ||
var authHeader = new Buffer(Settings.credentials.username + ':' + Settings.credentials.key).toString('base64'); | ||
reqOptions.headers['Authorization'] = 'Basic ' + authHeader; | ||
} | ||
@@ -59,7 +66,7 @@ | ||
var self = this; | ||
this.request = (Settings.use_ssl ? https: http).request(this.requestOptions, function (response) { | ||
this.request = (Settings.use_ssl ? https: http).request(this.reqOptions, function (response) { | ||
response.setEncoding('utf8'); | ||
if (response.statusCode === 302 || response.statusCode === 304) { | ||
Logger.info("Response " + response.statusCode + ' ' + self.requestOptions.method + " " + self.requestOptions.path); | ||
Logger.info('Response ' + response.statusCode + ' ' + self.reqOptions.method + ' ' + self.reqOptions.path); | ||
try { | ||
@@ -79,3 +86,3 @@ self.emit('success', {}, response); | ||
response.on('data', function (chunk) { | ||
if (self.requestOptions.method !== 'HEAD') { | ||
if (self.reqOptions.method !== 'HEAD') { | ||
flushed += chunk; | ||
@@ -111,3 +118,3 @@ } | ||
var logMethod = response.statusCode.toString().indexOf('5') == 0 ? 'error' : 'info'; | ||
Logger[logMethod]("Response " + response.statusCode + ' ' + self.requestOptions.method + " " + self.requestOptions.path, result); | ||
Logger[logMethod]('Response ' + response.statusCode + ' ' + self.reqOptions.method + ' ' + self.reqOptions.path, result); | ||
@@ -128,4 +135,4 @@ if (response.statusCode.toString().indexOf('2') === 0) { | ||
Logger.info("Request: " + this.requestOptions.method + " " + this.requestOptions.path, | ||
"\n - data: ", this.data, "\n - headers: ", JSON.stringify(this.requestOptions.headers)); | ||
Logger.info('Request: ' + this.reqOptions.method + ' ' + this.reqOptions.path, | ||
'\n - data: ', this.data, '\n - headers: ', JSON.stringify(this.reqOptions.headers)); | ||
@@ -153,3 +160,3 @@ this.request.write(this.data); | ||
var result; | ||
data = stripUnknown(data); | ||
data = stripUnknownChars(data); | ||
@@ -171,8 +178,6 @@ try { | ||
function stripUnknown(str) { | ||
var x = [], | ||
i = 0, | ||
il = str.length; | ||
function stripUnknownChars(str) { | ||
var x = [], i = 0, length = str.length; | ||
for (i; i < il; i++) { | ||
for (i; i < length; i++) { | ||
if (str.charCodeAt(i)) { | ||
@@ -179,0 +184,0 @@ x.push(str.charAt(i)); |
@@ -70,2 +70,3 @@ var fs = require('fs'), | ||
'click' : addElementCommand.call(this, 'elementIdClick'), | ||
'clearValue': addElementCommand.call(this, 'elementIdClear'), | ||
'getAttribute' : addElementCommand.call(this, 'elementIdAttribute', 1), | ||
@@ -72,0 +73,0 @@ 'getCssProperty' : addElementCommand.call(this, 'elementIdCssProperty', 1), |
@@ -263,3 +263,3 @@ var Actions = {}, | ||
return postRequest.call(this, "/frame", { | ||
"frameId": frameId | ||
"id": frameId | ||
}, callback); | ||
@@ -266,0 +266,0 @@ }; |
{ | ||
"name": "nightwatch", | ||
"description": "A node.js bindings implementation for selenium 2.0/webdriver", | ||
"version": "0.2.2", | ||
"version": "0.2.4", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Andrei Rusu", |
@@ -284,3 +284,3 @@ var protocol = require('../../lib/selenium/protocol.js'); | ||
test.equal(command.request.method, "POST"); | ||
test.equal(command.data, '{"frameId":"testFrame"}'); | ||
test.equal(command.data, '{"id":"testFrame"}'); | ||
test.equal(command.request.path, '/wd/hub/session/1352110219202/frame'); | ||
@@ -287,0 +287,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3648
5
34752441
12