Skip to content
Browse files

Started queue

  • Loading branch information...
1 parent 877d857 commit da3d523f698f8c302ac19af250a143fd35afc555 @tj tj committed
Showing with 45 additions and 13 deletions.
  1. +15 −11 examples/google.js
  2. +30 −2 lib/soda/client.js
View
26 examples/google.js
@@ -27,14 +27,18 @@ var browser = soda.createClient({
// });
// });
-browser.chain
- .open('/')
- .type('q', 'Hello World')
- .clickAndWait('btnG')
- .assertTitle('Hello World - Google Search')
- .testComplete()
- .done(function(err, res){
- console.log('done');
- console.dir(err)
- console.dir(res.body)
- });
+browser.session(function(){
+ browser
+ .chain
+ .open('/')
+ .type('q', 'Hello World')
+ .clickAndWait('btnG')
+ .assertTitle('Hello World - Google Search')
+ .testComplete()
+ .done(function(err, res){
+ console.log('done');
+ console.dir(err)
+ console.dir(res.body)
+ });
+});
+
View
32 lib/soda/client.js
@@ -121,6 +121,16 @@ Client.prototype.commandPath = function(cmd, args){
return '/selenium-server/driver/?' + qs.stringify(obj);
};
+Client.prototype.__defineGetter__('chain', function(){
+ this.queue = [];
+ return this;
+});
+
+Client.prototype.done = function(fn){
+ this.done = fn;
+ this.queue.shift()();
+};
+
/**
* Shortcut for `new selenium.Client()`.
*
@@ -260,9 +270,27 @@ exports.accessors.map(function(cmd){
exports.commands.map(function(cmd){
Client.prototype[cmd] = function(){
- var len = arguments.length
+ var self = this
+ , len = arguments.length
, fn = arguments[len - 1]
, args = Array.prototype.slice.call(arguments, 0, len - 1);
- return this.command(cmd, args, fn);
+ if (this.queue) {
+ console.log('queued %s', cmd);
+ this.queue.push(function(){
+ console.log('running %s', cmd);
+ self.command(cmd, args, function(err, res){
+ if (err) {
+ self.done(err, res);
+ } else if (self.queue.length) {
+ self.queue.shift()();
+ } else {
+ self.done(null, res);
+ }
+ });
+ });
+ return this;
+ } else {
+ return this.command(cmd, args, fn);
+ }
};
});

0 comments on commit da3d523

Please sign in to comment.
Something went wrong with that request. Please try again.