Commit 35ac229d 35ac229d31eeab364738f63f313b9935a9be71b3 by Nicolas Perriault

rewrote samples/googlematch.js using Casper#each()

1 parent cd69df4e
...@@ -30,25 +30,17 @@ if (terms.length < 2) { ...@@ -30,25 +30,17 @@ if (terms.length < 2) {
30 30
31 casper.start("http://google.fr/"); 31 casper.start("http://google.fr/");
32 32
33 casper.repeat(terms.length, function(self) { 33 casper.each(terms, function(self, term, i) {
34 self.then((function(casper, i) { 34 self.then(function(self) {
35 return function(self) { 35 self.fill('form[name=f]', { q: term }, true);
36 self.fill('form[name=f]', { 36 }).then(function(self) {
37 q: terms[i] 37 var score = self.fetchScore();
38 }, true);
39 };
40 })(self, i));
41 self.then((function(casper, i) {
42 return function(self) {
43 var term = terms[i], score = self.fetchScore();
44 scores.push({ 38 scores.push({
45 term: term, 39 term: term,
46 score: score 40 score: score
47 }); 41 });
48 self.echo(term + ': ' + score); 42 self.echo(term + ': ' + score);
49 }; 43 });
50 })(self, i));
51 i++;
52 }); 44 });
53 45
54 casper.run(function(self) { 46 casper.run(function(self) {
......