Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Strip ^OK, from response

  • Loading branch information...
commit 7a795cfd8d84cae150bb24923ca663c508c5fbab 1 parent 83f243b
@tj tj authored
Showing with 27 additions and 8 deletions.
  1. +2 −3 examples/google.js
  2. +25 −5 lib/selenium/client.js
View
5 examples/google.js
@@ -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
30 lib/selenium/client.js
@@ -32,13 +32,21 @@ 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; });
@@ -46,6 +54,9 @@ Client.prototype.command = function(name, args, fn){
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);
}
});
@@ -53,11 +64,20 @@ Client.prototype.command = function(name, args, fn){
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;
};
/**
Please sign in to comment.
Something went wrong with that request. Please try again.