Commit 100f22a7 100f22a78859b753990927fd95e3f45d14ba69f0 by Nicolas Perriault

added multirun.js code sample

1 parent 04416167
1 var casper = new phantom.Casper({
2 verbose: true
3 });
4
5 function countLinks() {
6 return document.querySelectorAll('a').length;
7 }
8
9 var suites = [
10 function(self) {
11 self.echo('Suite 1');
12 self.start('http://google.com/', function(self) {
13 self.echo('Page title: ' + self.getTitle());
14 }).then(function(self) {
15 self.echo(self.evaluate(countLinks) + ' links');
16 });
17 },
18 function(self) {
19 self.echo('Suite 2');
20 self.start('http://yahoo.com/', function(self) {
21 self.echo('Page title: ' + self.getTitle());
22 }).then(function(self) {
23 self.echo(self.evaluate(countLinks) + ' links');
24 });
25 },
26 function(self) {
27 self.echo('Suite 3');
28 self.start('http://bing.com/', function(self) {
29 self.echo('Page title: ' + self.getTitle());
30 }).then(function(self) {
31 self.echo(self.evaluate(countLinks) + ' links');
32 });
33 }
34 ];
35
36 casper.start().then(function(self) {
37 self.echo('Starting');
38 });
39
40 var currentSuite = 0;
41
42 function check(self) {
43 if (suites[currentSuite]) {
44 suites[currentSuite](casper);
45 currentSuite++;
46 casper.run(check);
47 } else {
48 self.echo('All done.').exit();
49 }
50 }
51
52 casper.run(check);