Permalink
Browse files

Started command usage

  • Loading branch information...
1 parent 5ba1a88 commit 1543c1e0e1ce05611bb76d25ebf170def2d831a8 @tj tj committed Sep 3, 2010
Showing with 45 additions and 0 deletions.
  1. +16 −0 examples/google.js
  2. +2 −0 index.js
  3. +27 −0 lib/selenium/client.js
View
@@ -0,0 +1,16 @@
+
+/**
+ * Module dependencies.
+ */
+
+var selenium = require('../index');
+
+var client = selenium.createClient({
+ host: 'localhost',
+ port: 4444,
+ url: 'http://www.google.com'
+});
+
+client.command('getNewBrowserSession', ['*firefox', 'http://google.com'], function(){
+
+});
View
@@ -0,0 +1,2 @@
+
+module.exports = require('./lib/selenium');
@@ -6,6 +6,12 @@
*/
/**
+ * Module dependencies.
+ */
+
+var http = require('http');
+
+/**
* Initialize a `Client` with the given `options`.
*
* Options:
@@ -26,6 +32,27 @@ var Client = exports = module.exports = function Client(options) {
this.url = options.url;
};
+Client.prototype.command = function(name, args, fn){
+ var client = http.createClient(this.port, this.host);
+ var req = client.request('GET'
+ , this.commandURL(name, args)
+ , { Host: this.host + (this.port ? ':' + this.port : '') });
+ req.on('response', function(res){
+ res.body = '';
+ res.setEncoding('utf8');
+ res.on('data', function(chunk){ res.body += chunk; });
+ res.on('end', function(){ fn(null, res); });
+ });
+ req.end();
+};
+
+Client.prototype.commandURL = function(name, args){
+ args = args.map(function(arg, i){
+ return i + 1 + '=' + encodeURIComponent(arg);
+ }).join('&');
+ return '/selenium-server/driver/?cmd=' + name + '&' + args;
+};
+
/**
* Shortcut for `new selenium.Client()`.
*

0 comments on commit 1543c1e

Please sign in to comment.