Commit e429daff e429daff0eb9f99544e998cc329e03bd84bb31dd by Nicolas Perriault

closes #24 - added custom logging example

1 parent f7787f50
1 phantom.injectJs('casper.js');
2
3 var casper = new phantom.Casper({
4 onResourceReceived: function(self, resource) {
5 var infos = [
6 resource.url,
7 resource.status,
8 resource.statusText,
9 resource.redirectURL,
10 resource.bodySize
11 ];
12 resource.headers.forEach(function(header) {
13 infos.push('[' + [header.name, header.value].join(', ') + ']');
14 });
15 self.log(infos.join(', '), 'verbose');
16 },
17 verbose: true,
18 logLevel: 'verbose'
19 });
20
21 casper.logLevels = ['verbose'].concat(casper.logLevels);
22
23 casper.start('http://www.google.com/').run(function(self) {
24 self.exit();
25 });
...@@ -6,8 +6,6 @@ var links = [ ...@@ -6,8 +6,6 @@ var links = [
6 'http://bing.com/' 6 'http://bing.com/'
7 ]; 7 ];
8 var casper = new phantom.Casper(); 8 var casper = new phantom.Casper();
9 var i = 0;
10 var titles = [];
11 9
12 casper.start(); 10 casper.start();
13 11
......
...@@ -6,7 +6,7 @@ var casper = new phantom.Casper(); ...@@ -6,7 +6,7 @@ var casper = new phantom.Casper();
6 function getLinks() { 6 function getLinks() {
7 var links = document.querySelectorAll('h3.r a'); 7 var links = document.querySelectorAll('h3.r a');
8 return Array.prototype.map.call(links, function(e) { 8 return Array.prototype.map.call(links, function(e) {
9 return e.getAttribute('href') 9 return e.getAttribute('href');
10 }); 10 });
11 } 11 }
12 12
......
...@@ -47,7 +47,7 @@ casper.start('tests/site/index.html', function(self) { ...@@ -47,7 +47,7 @@ casper.start('tests/site/index.html', function(self) {
47 self.click('a[href="test.html"]'); 47 self.click('a[href="test.html"]');
48 }); 48 });
49 49
50 casper.test.assert(casper.steps.length === 1, 'Casper.start() can add a new navigation step'); 50 casper.test.assertEquals(casper.steps.length, 2, 'Casper.start() can add a new navigation step');
51 51
52 // Casper.viewport() 52 // Casper.viewport()
53 casper.test.comment('viewport'); 53 casper.test.comment('viewport');
...@@ -63,7 +63,7 @@ casper.then(function(self) { ...@@ -63,7 +63,7 @@ casper.then(function(self) {
63 self.click('a[href="form.html"]'); 63 self.click('a[href="form.html"]');
64 }); 64 });
65 65
66 casper.test.assert(casper.steps.length === 2, 'Casper.then() adds a new navigation step'); 66 casper.test.assert(casper.steps.length === 3, 'Casper.then() adds a new navigation step');
67 67
68 // Casper#capture() 68 // Casper#capture()
69 casper.test.comment('capturing'); 69 casper.test.comment('capturing');
......