diff --git a/lib/client.js b/lib/client.js index ede3660..bf60932 100644 --- a/lib/client.js +++ b/lib/client.js @@ -11,7 +11,7 @@ Client.create = function() { var instance = Object.create(proto); constructor.apply(instance, arguments); return instance; -} +}; /** * Constructor @@ -24,7 +24,7 @@ function constructor(opts) { this.path = opts.path || ''; underscore.bindAll.call(underscore, [this] + this._bound); -}; +} /** * Specifies which methods are bound to the instance. @@ -75,7 +75,7 @@ proto.request = function(method, resource, data, callback) { options.headers['Content-Length'] = data.length; } - req = http.request(options) + req = http.request(options); // Buffer up the response body and proceed. req.on('response', function(res) { @@ -129,7 +129,7 @@ proto._requestDidComplete = function(res, body, callback) { // Automatically follow redirects. if (code >= 300 && code < 400) { - return this.get(res.headers['location'], callback); + return this.get(res.headers.location, callback); } if (!type.match('application/json')) { @@ -161,7 +161,7 @@ proto._requestDidComplete = function(res, body, callback) { proto._requestDidFail = function(res, body, cb) { var type, data, error; - type = res.headers['content-type'] || "" + type = res.headers['content-type'] || ""; // The content-type is expected to be text/plain. if (type !== 'text/plain') { @@ -187,5 +187,9 @@ proto._requestDidFail = function(res, body, cb) { error = res.statusCode === 404 ? "Unknown command" : "Unknown error"; } + if (typeof error === 'string') { + error = new Error(error); + } + cb(error); }; diff --git a/lib/endpoint.js b/lib/endpoint.js index f6e7b6b..f1fed0f 100644 --- a/lib/endpoint.js +++ b/lib/endpoint.js @@ -31,7 +31,7 @@ function constructor(opts) { , port: opts.port , path: opts.path }); -}; +} /** * Retrieves status of the endpoint. @@ -43,7 +43,7 @@ proto.status = function(callback) { if (err) { return callback(err); } - + callback(null, res.value); }); }; diff --git a/lib/session.js b/lib/session.js index af490da..0821be2 100644 --- a/lib/session.js +++ b/lib/session.js @@ -72,11 +72,14 @@ proto.execute = function(fn, args, callback) { if (typeof args === 'function') { callback = args; - args = []; + args = null; } + + args = args || []; + this.post('/execute', {script: fn, args: args}, function(err, res) { if (err) { - callback(err); + return callback(err); } callback(null, res.value); diff --git a/test/endpoint_test.js b/test/endpoint_test.js index 2f60f65..de5ad1f 100644 --- a/test/endpoint_test.js +++ b/test/endpoint_test.js @@ -1,3 +1,5 @@ +/*global suite test*/ + var assert = require('chai').assert , spy = require('sinon').spy , Endpoint = require('webdriver/lib/endpoint') diff --git a/test/session_test.js b/test/session_test.js index e59bb3c..22d17f8 100644 --- a/test/session_test.js +++ b/test/session_test.js @@ -1,3 +1,5 @@ +/*global suite test*/ + var assert = require('chai').assert ,spy = require('sinon').spy , Session = require('webdriver/lib/session'); @@ -32,6 +34,7 @@ suite('Session', function() { assert.instanceOf(session, Session); }); }); // constructor + suite('request', function() { var method = 'GET' , resource = '/foo' @@ -54,6 +57,7 @@ suite('Session', function() { assert.equal(args[3], callback, 'callback is not modified'); }); }); // request + suite('url', function() { test('retrieves url when called without string', function() { var client = fakeClient() @@ -71,6 +75,7 @@ suite('Session', function() { assert.equal(args[2], null, 'params are not defined'); assert.equal(args[3], callback, 'callback is passed'); }); + test('navigates to url when called with a string', function() { var client = fakeClient() , session = Session.create({id: 1, client: client})