robotremote
Advanced tools
Comparing version 0.9.4 to 0.9.5
@@ -7,5 +7,13 @@ 'use strict'; | ||
var client = new robot.Client({host: 'localhost', port: 8270}, function(lib){ | ||
repl.start('robot> ').context.lib = lib; | ||
var options = {host: process.argv[2], port: parseInt(process.argv[3], 10) }; | ||
var serverString = options.host + ':' + options.port; | ||
robot.createClient(options).then(function (keywords) { | ||
console.log('Connected to remote server at "' + serverString + '"'); | ||
console.log('Available keywords: ' + Object.keys(keywords).join(', ')); | ||
repl.start(serverString + '> ').context.keywords = keywords; | ||
}, function (err) { | ||
console.log('Could not connected to remote server at "' + serverString + '"'); | ||
throw err; | ||
}); | ||
@@ -7,3 +7,3 @@ 'use strict'; | ||
function Server(libraries, options) { | ||
function Server(libraries, options, listeningCallback) { | ||
this.host = options.host; | ||
@@ -35,3 +35,3 @@ this.port = options.port; | ||
this.server = xmlrpc.createServer(options); | ||
this.server = xmlrpc.createServer(options, listeningCallback); | ||
@@ -114,3 +114,3 @@ // TODO trovare modo migliore per fargliele riferire e anche illog dentro con va col ctrl C | ||
result.error = val.toString(); | ||
result.contibuable = val.continuable === true || false; | ||
result.continuable = val.continuable === true || false; | ||
result.fatal = val.fatal === true || false; | ||
@@ -179,32 +179,47 @@ } else { | ||
* Create a new client with given options | ||
* @param options a dictionary with xmlrpc options. Also path is supported. | ||
* @param options a dictionary with xmlrpc options. | ||
* @param ready callback to call when the client is ready. | ||
* @constructor | ||
*/ | ||
function Client(options, ready) { | ||
options.path = '/'; | ||
var client = xmlrpc.createClient(options); | ||
this.client = client; | ||
var that = this; | ||
client.methodCall('get_keyword_names', [], function (err, val) { | ||
val.forEach(function (keywordName) { | ||
that[keywordName] = function () { | ||
var arrayArguments = Array.prototype.slice.call(arguments); | ||
var cb = arrayArguments.pop(); | ||
var args = [keywordName, arrayArguments]; | ||
client.methodCall('run_keyword', args, cb); | ||
}; | ||
client.methodCall('get_keyword_arguments', [keywordName], function (err, val) { | ||
that[keywordName].args = val; | ||
function createClient(options) { | ||
var Promise = require('promise'); | ||
var result = new Promise(function (resolve, reject) { | ||
options.path = '/'; | ||
var client = xmlrpc.createClient(options); | ||
var keywords = {}; | ||
client.methodCall('get_keyword_names', [], function (err, val) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
val.forEach(function (keywordName) { | ||
keywords[keywordName] = function () { | ||
var arrayArguments = Array.prototype.slice.call(arguments); | ||
var args = [keywordName, arrayArguments]; | ||
var promise = new Promise(function (resolve, reject) { | ||
client.methodCall('run_keyword', args, function (err, res) { | ||
if (err) { | ||
reject(err); | ||
} else if (res.status === 'PASS') { | ||
resolve(res); | ||
} else { | ||
reject(res); | ||
} | ||
}); | ||
}); | ||
return promise; | ||
}; | ||
client.methodCall('get_keyword_arguments', [keywordName], function (err, val) { | ||
keywords[keywordName].args = val; | ||
}); | ||
client.methodCall('get_keyword_documentation', [keywordName], function (err, val) { | ||
keywords[keywordName].docs = val; | ||
}); | ||
}); | ||
client.methodCall('get_keyword_documentation', [keywordName], function (err, val) { | ||
that[keywordName].docs = val; | ||
}); | ||
resolve(keywords); | ||
}); | ||
if (ready !== undefined) { | ||
ready(that); | ||
} | ||
}); | ||
return result; | ||
} | ||
module.exports.Client = Client; | ||
module.exports.createClient = createClient; |
@@ -17,3 +17,3 @@ { | ||
], | ||
"version": "0.9.4", | ||
"version": "0.9.5", | ||
"preferGlobal": false, | ||
@@ -35,3 +35,4 @@ "homepage": "https://github.com/comick/node-robotremoteserver", | ||
"lib": "./lib", | ||
"example": "./example" | ||
"example": "./example", | ||
"bin": "./bin" | ||
}, | ||
@@ -44,3 +45,4 @@ "main": "./lib/robotremote.js", | ||
"devDependencies": { | ||
"promise": ">=6.0.1" | ||
"promise": ">=6.0.1", | ||
"mocha": ">=1.21.5" | ||
}, | ||
@@ -51,3 +53,3 @@ "optionalDependencies": { | ||
"scripts": { | ||
"test": "pybot test" | ||
"test": "mocha && pybot test" | ||
}, | ||
@@ -54,0 +56,0 @@ "engines": { |
@@ -113,33 +113,2 @@ # robotremote | ||
## Using the client | ||
The client is useful for testing keywords from the REPL: | ||
```js | ||
> var lib = new require('./lib/robotremote').Client({ host: 'localhost', port: 8270 }) | ||
> lib.stringsShouldBeEqual | ||
{ [Function] | ||
args: [ 'str1', 'str2' ], | ||
docs: '' } | ||
> lib.countItemsInDirectory | ||
{ [Function] | ||
args: [ 'path' ], | ||
docs: 'Returns the number of items in the directory specified by `path`.' } | ||
> lib.countItemsInDirectory(process.cwd(), function(e, v) { console.log(v) }) | ||
undefined | ||
> { status: 'PASS', | ||
output: '', | ||
traceback: '', | ||
return: 14, | ||
error: '' } | ||
> lib.stringsShouldBeEqual('bau', 'miao', function(e, v) { console.log(v) }) | ||
undefined | ||
> { status: 'FAIL', | ||
output: '', | ||
traceback: 'AssertionError: Given strings are not equal\n at Server.lib.stringsShouldBeEqual (/home/michele/sviluppo/node-robotremoteserver/example/examplelibrary.js:46:12)\n at Server.runKeyword (/home/michele/sviluppo/node-robotremoteserver/lib/robotremote.js:112:26)\n at Server.<anonymous> (/home/michele/sviluppo/node-robotremoteserver/lib/robotremote.js:43:21)\n at Server.EventEmitter.emit (events.js:106:17)\n at /home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/lib/server.js:42:14\n at callback (/home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/lib/deserializer.js:65:7)\n at Deserializer.onDone (/home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/lib/deserializer.js:92:12)\n at SAXStream.EventEmitter.emit (events.js:92:17)\n at Object.SAXStream._parser.onend (/home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/node_modules/sax/lib/sax.js:171:8)\n at emit (/home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/node_modules/sax/lib/sax.js:325:33)', | ||
return: '', | ||
error: 'AssertionError: Given strings are not equal' } | ||
> | ||
``` | ||
## License | ||
@@ -146,0 +115,0 @@ |
23905
12
396
2
138