Permalink
Browse files

Strip ^OK, from response

  • Loading branch information...
1 parent 83f243b commit 7a795cfd8d84cae150bb24923ca663c508c5fbab @tj tj committed Sep 3, 2010
Showing with 27 additions and 8 deletions.
  1. +2 −3 examples/google.js
  2. +25 −5 lib/selenium/client.js
View
@@ -11,7 +11,6 @@ var client = selenium.createClient({
url: 'http://www.google.com'
});
-client.command('getNewBrowserSessions', ['*firefox', 'http://google.com'], function(){
- console.dir(arguments[0])
- console.dir(arguments[1].body)
+client.command('getNewBrowserSession', ['*firefox', 'http://google.com'], function(err, res){
+ console.dir(res.body)
});
View
@@ -32,32 +32,52 @@ var Client = exports = module.exports = function Client(options) {
this.url = options.url;
};
-Client.prototype.command = function(name, args, fn){
+/**
+ * Execute the given `cmd` / `args`, then callback `fn(err, res)`.
+ *
+ * @param {String} cmd
+ * @param {Array} args
+ * @param {Function} fn
+ * @api private
+ */
+
+Client.prototype.command = function(cmd, args, fn){
var client = http.createClient(this.port, this.host);
var req = client.request('GET'
- , this.commandURL(name, args)
+ , this.commandPath(cmd, args)
, { Host: this.host + (this.port ? ':' + this.port : '') });
req.on('response', function(res){
- console.dir(res.statusCode)
res.body = '';
res.setEncoding('utf8');
res.on('data', function(chunk){ res.body += chunk; });
res.on('end', function(){
if (res.body.indexOf('ERROR') === 0) {
fn(new Error(res.body), res);
} else {
+ if (res.body.indexOf('OK') === 0) {
+ res.body = res.body.replace('OK,', '');
+ }
fn(null, res);
}
});
});
req.end();
};
-Client.prototype.commandURL = function(name, args){
+/**
+ * Construct a `cmd` path with the given `args`.
+ *
+ * @param {String} name
+ * @param {Array} args
+ * @return {String}
+ * @api private
+ */
+
+Client.prototype.commandPath = function(cmd, args){
args = args.map(function(arg, i){
return i + 1 + '=' + encodeURIComponent(arg);
}).join('&');
- return '/selenium-server/driver/?cmd=' + name + '&' + args;
+ return '/selenium-server/driver/?cmd=' + cmd + '&' + args;
};
/**

0 comments on commit 7a795cf

Please sign in to comment.