Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made soda use http.request() istead of the deprecated http.createClie…
…nt()
- Loading branch information
Manuel Goerlich
committed
Sep 19, 2012
1 parent
146e29d
commit 053c40b
Showing
1 changed file
with
33 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -14,14 +14,14 @@ var http = require('http') | ||
|
|
||
/** | /** | ||
* Initialize a `Client` with the given `options`. | * Initialize a `Client` with the given `options`. | ||
* | * | ||
* Options: | * Options: | ||
* | * | ||
* - `host` Hostname defaulting to localhost | * - `host` Hostname defaulting to localhost | ||
* - `port` Port number defaulting to 4444 | * - `port` Port number defaulting to 4444 | ||
* - `browser` Browser name | * - `browser` Browser name | ||
* - `url` URL string | * - `url` URL string | ||
* | * | ||
* @params {Object} options | * @params {Object} options | ||
* @api public | * @api public | ||
*/ | */ | ||
|
@@ -83,42 +83,41 @@ Client.prototype.session = function(fn){ | ||
Client.prototype.command = function(cmd, args, fn){ | Client.prototype.command = function(cmd, args, fn){ | ||
this.emit('command', cmd, args); | this.emit('command', cmd, args); | ||
|
|
||
// HTTP client | |||
var client = http.createClient(this.port, this.host); | |||
|
|||
// Path construction | // Path construction | ||
var path = this.commandPath(cmd, args); | 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 : '') } | |||
} | |||
This comment has been minimized.
Sorry, something went wrong. |
|||
|
|||
var req; | 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). | // 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 | // See also: http://jira.openqa.org/browse/SRC-50 | ||
if (path.length > 2048 && (this.host + path ).length > 2083) { | if (path.length > 2048 && (this.host + path ).length > 2083) { | ||
postData = this.commandPath(cmd, args).replace('/selenium-server/driver/?', ""); | var postData = this.commandPath(cmd, args).replace('/selenium-server/driver/?', ""); | ||
req = client.request('POST' |
|
||
, path | reqOptions.path = path; | ||
, { Host: this.host + (this.port ? ':' + this.port : '') | reqOptions.method = 'POST'; | ||
, 'Content-Length': postData.length | reqOptions.headers['Content-Length'] = postData.length; | ||
, 'Content-Type': 'application/x-www-form-urlencoded' | reqOptions.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
}); | |||
|
|||
req.write(postData); | |||
} else { | |||
req = client.request('GET' | |||
, path | |||
, { Host: this.host + (this.port ? ':' + this.port : '') }); | |||
} | } | ||
|
|||
req.on('response', function(res){ | req = http.request(reqOptions, function(res) { | ||
res.body = ''; | res.body = ''; | ||
res.setEncoding('utf8'); | res.setEncoding('utf8'); | ||
res.on('data', function(chunk){ res.body += chunk; }); | res.on('data', function(chunk){ res.body += chunk; }); | ||
res.on('end', function(){ | res.on('end', function(){ | ||
if (res.body.indexOf('ERROR') === 0 || | if (res.body.indexOf('ERROR') === 0 || | ||
res.body.indexOf('Timed out after ') === 0) { | res.body.indexOf('Timed out after ') === 0) { | ||
var err = res.body.replace(/^ERROR: */, ''); | var err = res.body.replace(/^ERROR: */, ''); | ||
err = cmd + '(' + args.join(', ') + '): ' + err; | err = cmd + '(' + args.join(', ') + '): ' + err; | ||
fn(new Error(err), res.body, res); | fn(new Error(err), res.body, res); | ||
} else { | } else { | ||
if (res.body.indexOf('OK') === 0) { | if (res.body.indexOf('OK') === 0) { | ||
|
@@ -127,9 +126,14 @@ Client.prototype.command = function(cmd, args, fn){ | ||
fn(null, res.body, res); | fn(null, res.body, res); | ||
} | } | ||
}); | }); | ||
return this; | |||
}); | }); | ||
|
|||
if(postData) { | |||
req.write(postData); | |||
} | |||
|
|||
req.end(); | req.end(); | ||
return this; | |||
}; | }; | ||
|
|
||
/** | /** | ||
|
@@ -190,7 +194,7 @@ Client.prototype.__defineGetter__('chain', function(){ | ||
*/ | */ | ||
|
|
||
Client.prototype.end = function(fn){ | 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 comment has been minimized.
Sorry, something went wrong. |
|||
this.queue.shift()(); | this.queue.shift()(); | ||
}; | }; | ||
|
|
||
|
@@ -262,7 +266,7 @@ exports.createClient = function(options){ | ||
|
|
||
/** | /** | ||
* Command names. | * Command names. | ||
* | * | ||
* @type Array | * @type Array | ||
*/ | */ | ||
|
|
||
|
@@ -362,7 +366,7 @@ exports.commands = [ | ||
|
|
||
/** | /** | ||
* Accessor names. | * Accessor names. | ||
* | * | ||
* @type Array | * @type Array | ||
*/ | */ | ||
|
|
||
|
@@ -423,13 +427,12 @@ exports.accessors = [ | ||
, 'PromptPresent' | , 'PromptPresent' | ||
, 'SomethingSelected' | , 'SomethingSelected' | ||
, 'TextPresent' | , 'TextPresent' | ||
, 'TextNotPresent' | |||
This comment has been minimized.
Sorry, something went wrong.
paulbjensen
|
|||
, 'Visible' | , 'Visible' | ||
]; | ]; | ||
|
|
||
/** | /** | ||
* Generate commands via accessors. | * Generate commands via accessors. | ||
* | * | ||
* All accessors get prefixed with: | * All accessors get prefixed with: | ||
* | * | ||
* - get | * - get | ||
|
missing semi-colon at line 96. Fixed locally, but this should get updated for those of us using jslint against everything.