webdriverjs
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -15,4 +15,5 @@ /** | ||
*/ | ||
var commandLoader = module.exports = function(scope){ | ||
var commandLoader = module.exports = function(scope, customCommands){ | ||
this.scope = scope; | ||
this.customCommands = customCommands; | ||
@@ -61,6 +62,14 @@ /** | ||
var customCommands = this.customCommands; | ||
for(var commandName in commands) { | ||
scope[commandName] = this.addQueueItem(commands[commandName],commandName); | ||
if(typeof this.customCommands[commandName] === 'undefined'){ | ||
scope[commandName] = this.addQueueItem(commands[commandName],commandName); | ||
} | ||
} | ||
for(var customCommandName in this.customCommands){ | ||
scope[customCommandName] = this.addQueueItem(customCommands[customCommandName],customCommandName); | ||
} | ||
}; | ||
@@ -67,0 +76,0 @@ |
@@ -7,3 +7,5 @@ /** | ||
var colors = require('./colors'); | ||
var fs = require('fs'), | ||
colors = require('./colors'), | ||
errorCodes = require('./errorCodes'); | ||
@@ -47,2 +49,5 @@ var log = function(args){ | ||
} | ||
// where to save the screenshots. default to current folder | ||
this.screenshotPath = ""; | ||
}; | ||
@@ -92,24 +97,84 @@ | ||
/** | ||
* helper method to log result messages | ||
* @param {Object} result result object | ||
*/ | ||
log._result = function (result) { | ||
if(typeof result === 'object') { | ||
result = JSON.stringify(result); | ||
} | ||
// prevent screenshot data output | ||
if(result.length > 1000) { | ||
result = '[Buffer] screenshot data'; | ||
} | ||
// if result is empty, dont prin't an empty string | ||
if(typeof result === 'string' && result.length === 0) { | ||
return; | ||
} | ||
if(result !== undefined && (this.logLevel === 'result' || this.logLevel === 'verbose')) { | ||
this.log(colors.teal + "RESULT\t\t " + colors.reset + result); | ||
} | ||
} | ||
/** | ||
* logs result messages | ||
* @param {Object} result result object | ||
* @param {Object} data data object | ||
* @param {Function} callback callback object | ||
*/ | ||
log.result = function(result) { | ||
log.result = function(result, data, callback) { | ||
var error = null; | ||
if(typeof result === 'object') { | ||
result = JSON.stringify(result); | ||
} | ||
if (result.status === 0) { | ||
this._result(result.value); | ||
} else if (result.status === 7 || result.status === 11) { | ||
error = { | ||
status: result.status, | ||
type: errorCodes[result.status].id, | ||
orgStatusMessage: errorCodes[result.status].message | ||
}; | ||
result.value = -1; | ||
// prevent screenshot data output | ||
if(result.length > 1000) { | ||
result = '[Buffer] screenshot data'; | ||
} | ||
this._result(errorCodes[result.status].id); | ||
} else { | ||
// if result is empty, dont prin't an empty string | ||
if(typeof result === 'string' && result.length === 0) { | ||
return; | ||
} | ||
if (errorCodes[result.status]) { | ||
this.error(errorCodes[result.status].id + "\t" + errorCodes[result.status].message + '\n\t\t\t' + result.value.message); | ||
} else { | ||
this.error(errorCodes["-1"].id + "\t" + errorCodes["-1"].message); | ||
} | ||
if(result !== undefined && (this.logLevel === 'result' || this.logLevel === 'verbose')) { | ||
this.log(colors.teal + "RESULT\t\t " + colors.reset + result); | ||
} | ||
error = { | ||
status: result.status, | ||
type: errorCodes[result.status].id, | ||
orgStatusMessage: errorCodes[result.status].message | ||
}; | ||
if (process.argv.length > 1) { | ||
var runner = process.argv[1].replace(/\.js/gi, ""); | ||
var prePath = ""; | ||
if (this.screenshotPath === "") { | ||
prePath = runner; | ||
} | ||
else { | ||
prePath = this.screenshotPath + runner.substring(runner.lastIndexOf("/") + 1); | ||
} | ||
// dont save the screenshot if its an unknown error | ||
if (result.status != 13) { | ||
var errorScreenshotFileName = prePath + "-ERROR." + errorCodes[result.status].id + ".png"; | ||
this.data('SAVING SCREENSHOT WITH FILENAME: '+errorScreenshotFileName); | ||
this.writeFile(errorScreenshotFileName, result.value.screen); | ||
} | ||
} | ||
} | ||
if (callback) { | ||
callback(error,result); | ||
} | ||
}; | ||
@@ -136,2 +201,9 @@ | ||
// saves screenshot to file | ||
log.writeFile = function(fileName, data, callback) { | ||
fs.writeFileSync(fileName, data, "base64", function(err) { | ||
callback(err); | ||
}); | ||
}; | ||
/** | ||
@@ -138,0 +210,0 @@ * helper method to check size ob object |
@@ -15,3 +15,3 @@ /** | ||
this.sessionID = null; | ||
this.startPath = '/wd/hub', | ||
this.startPath = '/wd/hub'; | ||
@@ -137,5 +137,2 @@ this.defaultOptions = { | ||
var self = this; | ||
var baseOptions = { saveScreenshotOnError: true}; | ||
return function(response) { | ||
@@ -175,58 +172,12 @@ | ||
log.result(result, data, function (err, res) { | ||
if (!this.sessionID) { | ||
log.error('NO SESSION, EXITING'); | ||
process.exit(1); | ||
} | ||
if (result.status === 0) { | ||
log.result(result.value); | ||
} else if (result.status === 7 || result.status === 11) { | ||
error = { | ||
status: result.status, | ||
type: errorCodes[result.status].id, | ||
orgStatusMessage: errorCodes[result.status].message | ||
}; | ||
result.value = -1; | ||
log.result(errorCodes[result.status].id); | ||
} else { | ||
if (errorCodes[result.status]) { | ||
log.error(errorCodes[result.status].id + "\t" + errorCodes[result.status].message + '\n\t\t\t' + result.value.message); | ||
} else { | ||
log.error(errorCodes["-1"].id + "\t" + errorCodes["-1"].message); | ||
} | ||
error = { | ||
status: result.status, | ||
type: errorCodes[result.status].id, | ||
orgStatusMessage: errorCodes[result.status].message | ||
}; | ||
if (process.argv.length > 1) { | ||
var runner = process.argv[1].replace(/\.js/gi, ""); | ||
var prePath = ""; | ||
if (self.screenshotPath === "") { | ||
prePath = runner; | ||
} | ||
else { | ||
prePath = self.screenshotPath + runner.substring(runner.lastIndexOf("/") + 1); | ||
} | ||
// dont save the screenshot if its an unknown error | ||
if (result.status != 13) { | ||
var errorScreenshotFileName = prePath + "-ERROR.AT." + self.currentQueueItem.commandName + ".png"; | ||
log.data('SAVING SCREENSHOT WITH FILENAME: '+errorScreenshotFileName); | ||
self.writeFile(errorScreenshotFileName, result.value.screen); | ||
} | ||
} | ||
} | ||
if (!this.sessionID) { | ||
log.error('NO SESSION, EXITING'); | ||
process.exit(1); | ||
} | ||
if (callback) { | ||
callback(error,result); | ||
} | ||
if (callback) { | ||
callback(err, res); | ||
} | ||
}.bind(this)); | ||
}.bind(this)); | ||
@@ -233,0 +184,0 @@ }.bind(this); |
@@ -34,5 +34,2 @@ /** | ||
// where to save the screenshots. default to current folder | ||
this.screenshotPath = ""; | ||
this.desiredCapabilities = { | ||
@@ -59,3 +56,7 @@ browserName: "firefox", | ||
// create CommandLoader and load implemented webdriverjs commands | ||
this.commandLoader = new CommandLoader(this); | ||
var customCommands = {}; | ||
if(options.hasOwnProperty('customCommands')){ | ||
customCommands = options.customCommands; | ||
} | ||
this.commandLoader = new CommandLoader(this, customCommands); | ||
this.commandLoader.load(['protocol','commands']); | ||
@@ -62,0 +63,0 @@ |
{ | ||
"name": "webdriverjs", | ||
"description": "A nodejs bindings implementation for selenium 2.0/webdriver", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"homepage": "https://github.com/Camme/webdriverjs", | ||
@@ -6,0 +6,0 @@ "author": "camilo tapia <camilo.tapia@gmail.com>", |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2195
4
34392975
96
7