Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made soda use http.request() istead of the deprecated http.createClient() #54

Merged
merged 1 commit into from
Sep 19, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 33 additions & 30 deletions lib/soda/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ var http = require('http')

/**
* Initialize a `Client` with the given `options`.
*
*
* Options:
*
*
* - `host` Hostname defaulting to localhost
* - `port` Port number defaulting to 4444
* - `browser` Browser name
* - `url` URL string
*
*
* @params {Object} options
* @api public
*/
Expand Down Expand Up @@ -83,42 +83,41 @@ Client.prototype.session = function(fn){
Client.prototype.command = function(cmd, args, fn){
this.emit('command', cmd, args);

// HTTP client
var client = http.createClient(this.port, this.host);

// Path construction
var path = this.commandPath(cmd, args);

// Assemble Request Options as far as possible
var reqOptions = {
host: this.host,
port: this.port,
path: path,
method: 'GET',
headers: { Host: this.host + (this.port ? ':' + this.port : '') }
}

var req;
// Selenium RC can support POST request: http://svn.openqa.org/fisheye/changelog/selenium-rc/?cs=1898,

// Selenium RC can support POST request: http://svn.openqa.org/fisheye/changelog/selenium-rc/?cs=1898,
// we need to switch to use POST if the URL's is too long (Below I use the Internet Explorer's limit).
// See also: http://jira.openqa.org/browse/SRC-50
if (path.length > 2048 && (this.host + path ).length > 2083) {
postData = this.commandPath(cmd, args).replace('/selenium-server/driver/?', "");
req = client.request('POST'
, path
, { Host: this.host + (this.port ? ':' + this.port : '')
, 'Content-Length': postData.length
, 'Content-Type': 'application/x-www-form-urlencoded'
});

req.write(postData);
} else {
req = client.request('GET'
, path
, { Host: this.host + (this.port ? ':' + this.port : '') });
var postData = this.commandPath(cmd, args).replace('/selenium-server/driver/?', "");

reqOptions.path = path;
reqOptions.method = 'POST';
reqOptions.headers['Content-Length'] = postData.length;
reqOptions.headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
req.on('response', function(res){

req = http.request(reqOptions, function(res) {
res.body = '';
res.setEncoding('utf8');
res.on('data', function(chunk){ res.body += chunk; });
res.on('end', function(){
if (res.body.indexOf('ERROR') === 0 ||
res.body.indexOf('Timed out after ') === 0) {
var err = res.body.replace(/^ERROR: */, '');
err = cmd + '(' + args.join(', ') + '): ' + err;
err = cmd + '(' + args.join(', ') + '): ' + err;
fn(new Error(err), res.body, res);
} else {
if (res.body.indexOf('OK') === 0) {
Expand All @@ -127,9 +126,14 @@ Client.prototype.command = function(cmd, args, fn){
fn(null, res.body, res);
}
});
return this;
});

if(postData) {
req.write(postData);
}

req.end();
return this;
};

/**
Expand Down Expand Up @@ -190,7 +194,7 @@ Client.prototype.__defineGetter__('chain', function(){
*/

Client.prototype.end = function(fn){
this._done = function(){this.queue = []; return fn.apply(this, arguments)};
this._done = function(){this.queue = null; return fn.apply(this, arguments)};
this.queue.shift()();
};

Expand Down Expand Up @@ -262,7 +266,7 @@ exports.createClient = function(options){

/**
* Command names.
*
*
* @type Array
*/

Expand Down Expand Up @@ -362,7 +366,7 @@ exports.commands = [

/**
* Accessor names.
*
*
* @type Array
*/

Expand Down Expand Up @@ -423,13 +427,12 @@ exports.accessors = [
, 'PromptPresent'
, 'SomethingSelected'
, 'TextPresent'
, 'TextNotPresent'
, 'Visible'
];

/**
* Generate commands via accessors.
*
*
* All accessors get prefixed with:
*
* - get
Expand Down