diff --git a/lib/soda/client.js b/lib/soda/client.js index 20348ac..d50094a 100755 --- a/lib/soda/client.js +++ b/lib/soda/client.js @@ -83,6 +83,11 @@ Client.prototype.session = function(fn){ Client.prototype.command = function(cmd, args, fn){ this.emit('command', cmd, args); + if (cmd === 'eval') { + fn(null, null, null); + return this; + } + // HTTP client var client = http.createClient(this.port, this.host); @@ -248,6 +253,21 @@ Client.prototype.and = function(fn){ return this; }; +/** + * Arbitrary callback when using the chaining api. + * Unlike and() this injects itself in the queue to only execute + * AFTER any existing selenium calls are completed. + */ +Client.prototype.then = function(fn){ + // Queue the command invocation + if (this.queue) { + return this.enqueue('eval', [fn]); + // Direct call + } else { + return this.command('eval', [], fn); + } +}; + /** * Shortcut for `new soda.Client()`. *