Commit 0c4095fb 0c4095fbe02780ed2f13149cad258c9154293057 by Nicolas Perriault

updated all samples to use the cli executable

1 parent 1b7e6c85
...@@ -3,7 +3,11 @@ ...@@ -3,7 +3,11 @@
3 * log every received resource. 3 * log every received resource.
4 * 4 *
5 */ 5 */
6 phantom.injectJs('casper.js'); 6
7 if (!phantom.casperLoaded) {
8 console.log('This script is intended to work with CasperJS, using its executable.');
9 phantom.exit(1);
10 }
7 11
8 var casper = new phantom.Casper({ 12 var casper = new phantom.Casper({
9 /** 13 /**
......
1 phantom.injectJs('casper.js'); 1 if (!phantom.casperLoaded) {
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
2 5
3 var logo; 6 var logo;
4 7
......
1 phantom.injectJs('casper.js'); 1 if (!phantom.casperLoaded) {
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
2 5
3 var links = [ 6 var links = [
4 'http://google.com/', 7 'http://google.com/',
......
1 phantom.injectJs("casper.js"); 1 if (!phantom.casperLoaded) {
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
2 5
3 var articles = []; 6 var articles = [];
4 7
......
1 phantom.injectJs('casper.js'); 1 if (!phantom.casperLoaded) {
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
2 5
3 var links = []; 6 var links = [];
4 var casper = new phantom.Casper(); 7 var casper = new phantom.Casper();
......
...@@ -9,6 +9,12 @@ ...@@ -9,6 +9,12 @@
9 * borris: 2370000 9 * borris: 2370000
10 * winner is "nicolas" with 69600000 results 10 * winner is "nicolas" with 69600000 results
11 */ 11 */
12
13 if (!phantom.casperLoaded) {
14 console.log('This script is intended to work with CasperJS, using its executable.');
15 phantom.exit(1);
16 }
17
12 phantom.Casper.extend({ 18 phantom.Casper.extend({
13 fetchScore: function() { 19 fetchScore: function() {
14 return this.evaluate(function() { 20 return this.evaluate(function() {
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
4 # 4 #
5 # (all arguments will be used as the query) 5 # (all arguments will be used as the query)
6 # 6 #
7 phantom.injectJs('casper.js') 7 if not phantom.casperLoaded
8 console.log "This script is intended to work with CasperJS, using its executable."
9 phantom.exit 1
8 10
9 links = [] 11 links = []
10 casper = new phantom.Casper 12 casper = new phantom.Casper
......
1 phantom.injectJs("casper.js"); 1 if (!phantom.casperLoaded) {
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
2 5
3 var casper = new phantom.Casper({ 6 var casper = new phantom.Casper({
4 logLevel: "debug" 7 logLevel: "debug"
......
1 phantom.injectJs('casper.js'); 1 if (!phantom.casperLoaded) {
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
5
2 var casper = new phantom.Casper({ 6 var casper = new phantom.Casper({
3 verbose: true, 7 verbose: true,
4 logLevel: 'debug' 8 logLevel: 'debug'
5 }) 9 });
10
6 casper.log('this is a debug message', 'debug'); 11 casper.log('this is a debug message', 'debug');
7 casper.log('and an informative one', 'info'); 12 casper.log('and an informative one', 'info');
8 casper.log('and a warning', 'warning'); 13 casper.log('and a warning', 'warning');
......
1 phantom.injectJs('casper.js'); 1 if (!phantom.casperLoaded) {
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
2 5
3 var casper = new phantom.Casper({ 6 var casper = new phantom.Casper({
4 logLevel: "debug", 7 logLevel: "debug",
......
1 phantom.injectJs('casper.js'); 1 if (!phantom.casperLoaded) {
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
2 5
3 var links = []; 6 var links = [];
4 var casper = new phantom.Casper({ 7 var casper = new phantom.Casper({
......
1 phantom.injectJs('casper.js'); 1 if (!phantom.casperLoaded) {
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
2 5
3 if (phantom.args.length === 0) { 6 if (phantom.casperArgs.args.length === 0) {
4 console.log('You must provide a timeout value') 7 console.log('You must provide a timeout value');
5 phantom.exit(1); 8 phantom.exit(1);
6 } else { 9 }
7 var timeout = Number(phantom.args[0], 10); 10
8 if (timeout < 1) { 11 var timeout = Number(phantom.casperArgs.args[0], 10);
9 console.log('A timeout value must be a positive integer') 12
13 if (timeout < 1) {
14 console.log('A timeout value must be a positive integer');
10 phantom.exit(1); 15 phantom.exit(1);
11 }
12 } 16 }
13 17
14 var casper = new phantom.Casper({ 18 var casper = new phantom.Casper({
15 // verbose: true,
16 // logLevel: "debug",
17 stepTimeout: timeout, 19 stepTimeout: timeout,
18 onStepTimeout: function(self) { 20 onStepTimeout: function(self) {
19 self.echo(self.requestUrl + ' failed to load in less than ' + timeout + 'ms', 'ERROR'); 21 self.echo(self.requestUrl + ' failed to load in less than ' + timeout + 'ms', 'ERROR');
...@@ -27,13 +29,17 @@ var links = [ ...@@ -27,13 +29,17 @@ var links = [
27 'http://cdiscount.fr/' 29 'http://cdiscount.fr/'
28 ]; 30 ];
29 31
32 casper.echo('Testing with timeout=' + timeout);
33
30 casper.start(); 34 casper.start();
35
31 casper.each(links, function(self, link, i) { 36 casper.each(links, function(self, link, i) {
32 self.test.comment('Adding ' + link + ' to test suite'); 37 self.test.comment('Adding ' + link + ' to test suite');
33 self.thenOpen(link, function(self) { 38 self.thenOpen(link, function(self) {
34 self.echo(self.requestUrl + ' loaded'); 39 self.echo(self.requestUrl + ' loaded');
35 }); 40 });
36 }); 41 });
42
37 casper.run(function(self) { 43 casper.run(function(self) {
38 self.test.renderResults(true); 44 self.test.renderResults(true);
39 self.exit(); 45 self.exit();
......
...@@ -14,15 +14,18 @@ ...@@ -14,15 +14,18 @@
14 * Will google.com load in less than 2000ms? 14 * Will google.com load in less than 2000ms?
15 * YES! 15 * YES!
16 */ 16 */
17 phantom.injectJs('casper.js'); 17 if (!phantom.casperLoaded) {
18 console.log('This script is intended to work with CasperJS, using its executable.');
19 phantom.exit(1);
20 }
18 21
19 if (phantom.args.length === 0) { 22 if (phantom.casperArgs.args.length === 0) {
20 console.log('You must provide a timeout value') 23 console.log('You must provide a timeout value');
21 phantom.exit(1); 24 phantom.exit(1);
22 } else { 25 } else {
23 var timeout = Number(phantom.args[0], 10); 26 var timeout = Number(phantom.casperArgs.args[0], 10);
24 if (timeout < 1) { 27 if (timeout < 1) {
25 console.log('A timeout value must be a positive integer') 28 console.log('A timeout value must be a positive integer');
26 phantom.exit(1); 29 phantom.exit(1);
27 } 30 }
28 } 31 }
......