Commit 0c56753a 0c56753a3e71c1e2b5b30d655a88eac1b7cab1b2 by Nicolas Perriault

Caster.waitFor 'then' parameter is now optional

1 parent 9d4432d9
Showing 1 changed file with 11 additions and 7 deletions
...@@ -637,8 +637,9 @@ ...@@ -637,8 +637,9 @@
637 * Waits until a function returns true to process a next step. 637 * Waits until a function returns true to process a next step.
638 * 638 *
639 * @param Function testFx A function to be evaluated for returning condition satisfecit 639 * @param Function testFx A function to be evaluated for returning condition satisfecit
640 * @param Function then The next step to perform 640 * @param Function then The next step to perform (optional)
641 * @param Number timeout The max amount of time to wait, in milliseconds 641 * @param Function onTimeout A callback function to call on timeout (optional)
642 * @param Number timeout The max amount of time to wait, in milliseconds (optional)
642 * @return Casper 643 * @return Casper
643 */ 644 */
644 waitFor: function(testFx, then, onTimeout, timeout) { 645 waitFor: function(testFx, then, onTimeout, timeout) {
...@@ -646,8 +647,8 @@ ...@@ -646,8 +647,8 @@
646 if (typeof testFx !== "function") { 647 if (typeof testFx !== "function") {
647 this.die("waitUntil() needs a test function"); 648 this.die("waitUntil() needs a test function");
648 } 649 }
649 if (typeof then !== "function") { 650 if (then && typeof then !== "function") {
650 this.die("waitUntil() needs a next step definition"); 651 this.die("waitUntil() next step definition must be a function");
651 } 652 }
652 this.delayedExecution = true; 653 this.delayedExecution = true;
653 var start = new Date().getTime(); 654 var start = new Date().getTime();
...@@ -667,7 +668,9 @@ ...@@ -667,7 +668,9 @@
667 clearInterval(interval); 668 clearInterval(interval);
668 } else { 669 } else {
669 self.log("waitFor() finished in " + (new Date().getTime() - start) + "ms.", "info"); 670 self.log("waitFor() finished in " + (new Date().getTime() - start) + "ms.", "info");
671 if (then) {
670 self.then(then); 672 self.then(then);
673 }
671 clearInterval(interval); 674 clearInterval(interval);
672 } 675 }
673 } 676 }
...@@ -680,8 +683,9 @@ ...@@ -680,8 +683,9 @@
680 * remote DOM to process a next step. 683 * remote DOM to process a next step.
681 * 684 *
682 * @param String selector A CSS3 selector 685 * @param String selector A CSS3 selector
683 * @param Function then The next step to perform 686 * @param Function then The next step to perform (optional)
684 * @param Number timeout The max amount of time to wait, in milliseconds 687 * @param Function onTimeout A callback function to call on timeout (optional)
688 * @param Number timeout The max amount of time to wait, in milliseconds (optional)
685 * @return Casper 689 * @return Casper
686 */ 690 */
687 waitForSelector: function(selector, then, onTimeout, timeout) { 691 waitForSelector: function(selector, then, onTimeout, timeout) {
...@@ -715,7 +719,7 @@ ...@@ -715,7 +719,7 @@
715 * @return Boolean 719 * @return Boolean
716 */ 720 */
717 this.click = function(selector) { 721 this.click = function(selector) {
718 var elem = document.querySelector(selector); 722 var elem = this.findOne(selector);
719 if (!elem) { 723 if (!elem) {
720 return false; 724 return false;
721 } 725 }
......