Commit f44d37b6 f44d37b6ae0a62ffcd54fd931ba004e696e32309 by Brikou CARRE

moved var declaration to the top

1 parent b1ed9a7e
...@@ -7,7 +7,7 @@ nbLinks = 0 ...@@ -7,7 +7,7 @@ nbLinks = 0
7 currentLink = 1 7 currentLink = 1
8 images = [] 8 images = []
9 9
10 # helper to hide some element from remote DOM 10 ### helper to hide some element from remote DOM ###
11 casper.hide = (selector) -> 11 casper.hide = (selector) ->
12 @evaluate (selector) -> 12 @evaluate (selector) ->
13 document.querySelector(selector).style.display = "none" 13 document.querySelector(selector).style.display = "none"
...@@ -17,7 +17,7 @@ casper.start "http://www.bbc.co.uk/", -> ...@@ -17,7 +17,7 @@ casper.start "http://www.bbc.co.uk/", ->
17 nbLinks = @evaluate -> 17 nbLinks = @evaluate ->
18 return __utils__.findAll('#promo2_carousel_items_items li').length 18 return __utils__.findAll('#promo2_carousel_items_items li').length
19 @echo "#{nbLinks} items founds" 19 @echo "#{nbLinks} items founds"
20 # hide navigation arrows 20 ### hide navigation arrows ###
21 @hide ".nav_left" 21 @hide ".nav_left"
22 @hide ".nav_right" 22 @hide ".nav_right"
23 @mouse.move "#promo2_carousel" 23 @mouse.move "#promo2_carousel"
...@@ -28,10 +28,10 @@ casper.start "http://www.bbc.co.uk/", -> ...@@ -28,10 +28,10 @@ casper.start "http://www.bbc.co.uk/", ->
28 @echo "Clicked on pause button" 28 @echo "Clicked on pause button"
29 @waitUntilVisible ".autoplay.nav_play", -> 29 @waitUntilVisible ".autoplay.nav_play", ->
30 @echo "Carousel has been paused" 30 @echo "Carousel has been paused"
31 # hide play button 31 ### hide play button ###
32 @hide ".autoplay" 32 @hide ".autoplay"
33 33
34 # Capture carrousel area 34 ### Capture carrousel area ###
35 next = -> 35 next = ->
36 image = "bbcshot#{currentLink}.png" 36 image = "bbcshot#{currentLink}.png"
37 images.push image 37 images.push image
...@@ -45,13 +45,13 @@ next = -> ...@@ -45,13 +45,13 @@ next = ->
45 else 45 else
46 @then buildPage 46 @then buildPage
47 47
48 # Building resulting page and image 48 ### Building resulting page and image ###
49 buildPage = -> 49 buildPage = ->
50 @echo "Build result page" 50 @echo "Build result page"
51 fs = require "fs" 51 fs = require "fs"
52 @viewport 624, 400 52 @viewport 624, 400
53 pageHtml = "<html><body style='background:black;margin:0;padding:0'>" 53 pageHtml = "<html><body style='background:black;margin:0;padding:0'>"
54 for image in images 54 images.forEach (image) ->
55 pageHtml += "<img src='file://#{fs.workingDirectory}/#{image}'><br>" 55 pageHtml += "<img src='file://#{fs.workingDirectory}/#{image}'><br>"
56 pageHtml += "</body></html>" 56 pageHtml += "</body></html>"
57 fs.write "result.html", pageHtml, 'w' 57 fs.write "result.html", pageHtml, 'w'
......
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
2 Create a mosaic image from all headline photos on BBC homepage 2 Create a mosaic image from all headline photos on BBC homepage
3 */ 3 */
4 4
5 var casper = require("casper").create(); 5 var buildPage, casper, currentLink, images, nbLinks, next;
6 var nbLinks = 0;
7 var currentLink = 1;
8 var images = [];
9 6
7 casper = require("casper").create();
8 nbLinks = 0;
9 currentLink = 1;
10 images = [];
11
12 /* helper to hide some element from remote DOM */
10 casper.hide = function(selector) { 13 casper.hide = function(selector) {
11 this.evaluate(function(selector) { 14 this.evaluate(function(selector) {
12 document.querySelector(selector).style.display = "none"; 15 document.querySelector(selector).style.display = "none";
...@@ -20,7 +23,7 @@ casper.start("http://www.bbc.co.uk/", function() { ...@@ -20,7 +23,7 @@ casper.start("http://www.bbc.co.uk/", function() {
20 return __utils__.findAll('#promo2_carousel_items_items li').length; 23 return __utils__.findAll('#promo2_carousel_items_items li').length;
21 }); 24 });
22 this.echo(nbLinks + " items founds"); 25 this.echo(nbLinks + " items founds");
23 // hide navigation arrows 26 /* hide navigation arrows */
24 this.hide(".nav_left"); 27 this.hide(".nav_left");
25 this.hide(".nav_right"); 28 this.hide(".nav_right");
26 this.mouse.move("#promo2_carousel"); 29 this.mouse.move("#promo2_carousel");
...@@ -31,14 +34,16 @@ casper.start("http://www.bbc.co.uk/", function() { ...@@ -31,14 +34,16 @@ casper.start("http://www.bbc.co.uk/", function() {
31 this.echo("Clicked on pause button"); 34 this.echo("Clicked on pause button");
32 this.waitUntilVisible(".autoplay.nav_play", function() { 35 this.waitUntilVisible(".autoplay.nav_play", function() {
33 this.echo("Carousel has been paused"); 36 this.echo("Carousel has been paused");
34 // hide play button 37 /* hide play button */
35 this.hide(".autoplay"); 38 this.hide(".autoplay");
36 }); 39 });
37 }); 40 });
38 }); 41 });
39 42
40 var next = function next() { 43 /* Capture carrousel area */
41 var image = "bbcshot" + currentLink + ".png"; 44 next = function() {
45 var image;
46 image = "bbcshot" + currentLink + ".png";
42 images.push(image); 47 images.push(image);
43 this.echo("Processing image " + currentLink); 48 this.echo("Processing image " + currentLink);
44 this.captureSelector(image, '.carousel_viewport'); 49 this.captureSelector(image, '.carousel_viewport');
...@@ -53,11 +58,13 @@ var next = function next() { ...@@ -53,11 +58,13 @@ var next = function next() {
53 } 58 }
54 }; 59 };
55 60
56 var buildPage = function buildPage() { 61 /* Building resulting page and image */
62 buildPage = function() {
63 var fs, pageHtml;
57 this.echo("Build result page"); 64 this.echo("Build result page");
58 var fs = require("fs"); 65 fs = require("fs");
59 this.viewport(624, 400); 66 this.viewport(624, 400);
60 var pageHtml = "<html><body style='background:black;margin:0;padding:0'>"; 67 pageHtml = "<html><body style='background:black;margin:0;padding:0'>";
61 images.forEach(function(image) { 68 images.forEach(function(image) {
62 pageHtml += "<img src='file://" + fs.workingDirectory + "/" + image + "'><br>"; 69 pageHtml += "<img src='file://" + fs.workingDirectory + "/" + image + "'><br>";
63 }); 70 });
......
1 casper = require("casper").create() 1 casper = require("casper").create()
2 dump = require("utils").dump 2 dump = require("utils").dump
3 3
4 # removing default options passed by the Python executable 4 ### removing default options passed by the Python executable ###
5 casper.cli.drop "cli" 5 casper.cli.drop "cli"
6 casper.cli.drop "casper-path" 6 casper.cli.drop "casper-path"
7 7
......
1 var casper = require("casper").create(); 1 var casper, dump;
2 var dump = require("utils").dump;
3 2
4 // removing default options passed by the Python executable 3 casper = require("casper").create();
4 dump = require("utils").dump;
5
6 /* removing default options passed by the Python executable */
5 casper.cli.drop("cli"); 7 casper.cli.drop("cli");
6 casper.cli.drop("casper-path"); 8 casper.cli.drop("casper-path");
7 9
......
1 casper = require("casper").create() 1 casper = require("casper").create()
2 2
3 # listening to a custom event 3 ### listening to a custom event ###
4 casper.on 'google.loaded', (title) -> 4 casper.on "google.loaded", (title) ->
5 casper.echo "Google page title is #{title}" 5 casper.echo "Google page title is #{title}"
6 6
7 casper.start "http://google.com/", -> 7 casper.start "http://google.com/", ->
8 # emitting a custom event 8 ### emitting a custom event ###
9 @emit 'google.loaded', @getTitle() 9 @emit "google.loaded", @getTitle()
10 10
11 casper.run() 11 casper.run()
......
1 var casper = require("casper").create(); 1 var casper;
2 2
3 // listening to a custom event 3 casper = require("casper").create();
4 casper.on('google.loaded', function(title) { 4
5 /* listening to a custom event */
6 casper.on("google.loaded", function(title) {
5 casper.echo("Google page title is " + title); 7 casper.echo("Google page title is " + title);
6 }); 8 });
7 9
8 casper.start("http://google.com/", function() { 10 casper.start("http://google.com/", function() {
9 // emitting a custom event 11 /* emitting a custom event */
10 this.emit('google.loaded', this.getTitle()); 12 this.emit("google.loaded", this.getTitle());
11 }); 13 });
12 14
13 casper.run(); 15 casper.run();
......
1 ### 1 ###
2 A basic custom logging implementation. The idea is to (extremely) verbosely 2 A basic custom logging implementation. The idea is to (extremely) verbosely log
3 log every received resource. 3 every received resource.
4 ### 4 ###
5 5
6 casper = require("casper").create 6 casper = require("casper").create
7 # Every time a resource is received, a new log entry is added to the stack 7 ###
8 # at the 'verbose' level. 8 Every time a resource is received, a new log entry is added to the stack at
9 the 'verbose' level.
10 ###
9 onResourceReceived: (self, resource) -> 11 onResourceReceived: (self, resource) ->
10 infos = [] 12 infos = []
11 props = ["url", "status", "statusText", "redirectURL", "bodySize"] 13 props = [
14 "url"
15 "status"
16 "statusText"
17 "redirectURL"
18 "bodySize"
19 ]
12 infos.push resource[prop] for prop in props 20 infos.push resource[prop] for prop in props
13 infos.push "[#{h.name}: #{h.value}]" for h in resource.headers 21 infos.push "[#{header.name}: #{header.value}]" for header in resource.headers
14 @log infos.join(', '), 'verbose' 22 @log infos.join(", "), "verbose"
15 verbose: true # we want to see the log printed out to the console 23 verbose: true # we want to see the log printed out to the console
16 logLevel: 'verbose' # of course we want to see logs to our new level :) 24 logLevel: "verbose" # of course we want to see logs to our new level :)
17 25
26 ### add a new 'verbose' logging level at the lowest priority ###
27 casper.logLevels = ["verbose"].concat casper.logLevels
18 28
19 # add a new 'verbose' logging level at the lowest priority 29 ### test our new logger with google ###
20 casper.logLevels = ['verbose'].concat casper.logLevels
21
22 # test our new logger with google
23 casper.start "http://www.google.com/" 30 casper.start "http://www.google.com/"
24 casper.run() 31 casper.run()
......
1 /* 1 /*
2 A basic custom logging implementation. The idea is to (extremely) verbosely 2 A basic custom logging implementation. The idea is to (extremely) verbosely log
3 log every received resource. 3 every received resource.
4 */ 4 */
5 5
6 var casper = require("casper").create({ 6 var casper;
7 /** 7
8 * Every time a resource is received, a new log entry is added to the stack 8 casper = require("casper").create({
9 * at the 'verbose' level. 9 /*
10 * 10 Every time a resource is received, a new log entry is added to the stack at
11 * @param Object resource A phantomjs resource object 11 the 'verbose' level.
12 */ 12 */
13 onResourceReceived: function(self, resource) { 13 onResourceReceived: function(self, resource) {
14 var infos = [ 14 var header, infos, prop, props, _i, _j, _len, _len1, _ref;
15 resource.url, 15 infos = [];
16 resource.status, 16 props = [
17 resource.statusText, 17 "url",
18 resource.redirectURL, 18 "status",
19 resource.bodySize 19 "statusText",
20 "redirectURL",
21 "bodySize"
20 ]; 22 ];
21 resource.headers.forEach(function(header) { 23 for (_i = 0, _len = props.length; _i < _len; _i++) {
22 infos.push('[' + [header.name, header.value].join(', ') + ']'); 24 prop = props[_i];
23 }); 25 infos.push(resource[prop]);
24 self.log(infos.join(', '), 'verbose'); 26 }
27 _ref = resource.headers;
28 for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
29 header = _ref[_j];
30 infos.push("[" + header.name + ": " + header.value + "]");
31 }
32 this.log(infos.join(", "), "verbose");
25 }, 33 },
26 verbose: true, // we want to see the log printed out to the console 34 verbose: true,
27 logLevel: 'verbose' // of course we want to see logs to our new level :) 35 logLevel: "verbose"
28 }); 36 });
29 37
30 // add a new 'verbose' logging level at the lowest priority 38 /* add a new 'verbose' logging level at the lowest priority */
31 casper.logLevels = ['verbose'].concat(casper.logLevels); 39 casper.logLevels = ["verbose"].concat(casper.logLevels);
32 40
33 // test our new logger with google 41 /* test our new logger with google */
34 casper.start("http://www.google.com/").run(function(self) { 42 casper.start("http://www.google.com/");
35 self.exit(); 43
36 }); 44 casper.run();
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
2 Download the google logo image as base64 2 Download the google logo image as base64
3 */ 3 */
4 4
5 var casper = require("casper").create({ 5 var casper;
6
7 casper = require("casper").create({
6 verbose: true 8 verbose: true
7 }); 9 });
8 10
......
1 casper = require("casper").create verbose: true 1 casper = require("casper").create
2 verbose: true
2 3
3 # If we don't set a limit, it could go on forever 4 ### If we don't set a limit, it could go on forever ###
4 upTo = ~~casper.cli.get(0) || 10 # max 10 links 5 upTo = ~~casper.cli.get(0) || 10
5 6
6 # Fetch all <a> elements from the page and return 7 ###
7 # the ones which contains a href starting with 'http://' 8 Fetch all <a> elements from the page and return
9 the ones which contains a href starting with 'http://'
10 ###
8 searchLinks = -> 11 searchLinks = ->
9 filter = Array::filter 12 filter = Array::filter
10 map = Array::map 13 map = Array::map
...@@ -13,20 +16,22 @@ searchLinks = -> ...@@ -13,20 +16,22 @@ searchLinks = ->
13 ), (a) -> 16 ), (a) ->
14 a.getAttribute "href" 17 a.getAttribute "href"
15 18
16 # The base links array 19 ### The base links array ###
17 links = [ 20 links = [
18 'http://google.com/' 21 "http://google.com/"
19 'http://yahoo.com/' 22 "http://yahoo.com/"
20 'http://bing.com/' 23 "http://bing.com/"
21 ] 24 ]
22 25
23 # Just opens the page and prints the title 26 ### Just opens the page and prints the title ###
24 start = (link) -> 27 start = (link) ->
25 @start link, -> 28 @start link, ->
26 @echo "Page title: #{ @getTitle() }" 29 @echo "Page title: #{ @getTitle() }"
27 30
28 # Get the links, and add them to the links array 31 ###
29 # (It could be done all in one step, but it is intentionally splitted) 32 Get the links, and add them to the links array
33 (It could be done all in one step, but it is intentionally splitted)
34 ###
30 addLinks = (link) -> 35 addLinks = (link) ->
31 @then -> 36 @then ->
32 found = @evaluate searchLinks 37 found = @evaluate searchLinks
...@@ -35,11 +40,12 @@ addLinks = (link) -> ...@@ -35,11 +40,12 @@ addLinks = (link) ->
35 40
36 casper.start() 41 casper.start()
37 42
38 casper.then -> @echo "Starting" 43 casper.then ->
44 @echo "Starting"
39 45
40 currentLink = 0; 46 currentLink = 0;
41 47
42 # As long as it has a next link, and is under the maximum limit, will keep running 48 ### As long as it has a next link, and is under the maximum limit, will keep running ###
43 check = -> 49 check = ->
44 if links[currentLink] && currentLink < upTo 50 if links[currentLink] && currentLink < upTo
45 @echo "--- Link #{currentLink} ---" 51 @echo "--- Link #{currentLink} ---"
......
1 var casper = require("casper").create({ 1 var addLinks, casper, check, currentLink, links, searchLinks, start, upTo;
2
3 casper = require("casper").create({
2 verbose: true 4 verbose: true
3 }); 5 });
4 6
5 // If we don't set a limit, it could go on forever 7 /* If we don't set a limit, it could go on forever */
6 var upTo = ~~casper.cli.get(0) || 10; // max 10 links 8 upTo = ~~casper.cli.get(0) || 10;
7 9
8 // Fetch all <a> elements from the page and return 10 /*
9 // the ones which contains a href starting with 'http://' 11 Fetch all <a> elements from the page and return
10 var searchLinks = function searchLinks() { 12 the ones which contains a href starting with 'http://'
11 var filter = Array.prototype.filter; 13 */
12 var map = Array.prototype.map; 14 searchLinks = function() {
15 var filter, map;
16 filter = Array.prototype.filter;
17 map = Array.prototype.map;
13 return map.call(filter.call(document.querySelectorAll("a"), function(a) { 18 return map.call(filter.call(document.querySelectorAll("a"), function(a) {
14 return /^http:\/\/.*/i.test(a.getAttribute("href")); 19 return /^http:\/\/.*/i.test(a.getAttribute("href"));
15 }), function(a) { 20 }), function(a) {
...@@ -17,25 +22,28 @@ var searchLinks = function searchLinks() { ...@@ -17,25 +22,28 @@ var searchLinks = function searchLinks() {
17 }); 22 });
18 }; 23 };
19 24
20 // The base links array 25 /* The base links array */
21 var links = [ 26 links = [
22 'http://google.com/', 27 "http://google.com/",
23 'http://yahoo.com/', 28 "http://yahoo.com/",
24 'http://bing.com/' 29 "http://bing.com/"
25 ]; 30 ];
26 31
27 // Just opens the page and prints the title 32 /* Just opens the page and prints the title */
28 var start = function start(link) { 33 start = function(link) {
29 this.start(link, function() { 34 this.start(link, function() {
30 this.echo("Page title: " + (this.getTitle())); 35 this.echo("Page title: " + this.getTitle());
31 }); 36 });
32 }; 37 };
33 38
34 // Get the links, and add them to the links array 39 /*
35 // (It could be done all in one step, but it is intentionally splitted) 40 Get the links, and add them to the links array
36 var addLinks = function addLinks(link) { 41 (It could be done all in one step, but it is intentionally splitted)
42 */
43 addLinks = function(link) {
37 this.then(function() { 44 this.then(function() {
38 var found = this.evaluate(searchLinks); 45 var found;
46 found = this.evaluate(searchLinks);
39 this.echo(found.length + " links found on " + link); 47 this.echo(found.length + " links found on " + link);
40 links = links.concat(found); 48 links = links.concat(found);
41 }); 49 });
...@@ -47,10 +55,10 @@ casper.then(function() { ...@@ -47,10 +55,10 @@ casper.then(function() {
47 this.echo("Starting"); 55 this.echo("Starting");
48 }); 56 });
49 57
50 var currentLink = 0; 58 currentLink = 0;
51 59
52 // As long as it has a next link, and is under the maximum limit, will keep running 60 /* As long as it has a next link, and is under the maximum limit, will keep running */
53 var check = function check() { 61 check = function() {
54 if (links[currentLink] && currentLink < upTo) { 62 if (links[currentLink] && currentLink < upTo) {
55 this.echo("--- Link " + currentLink + " ---"); 63 this.echo("--- Link " + currentLink + " ---");
56 start.call(this, links[currentLink]); 64 start.call(this, links[currentLink]);
......
1 casper = require("casper").create() 1 casper = require("casper").create()
2 2
3 links = [ 3 links = [
4 'http://google.com/' 4 "http://google.com/"
5 'http://yahoo.com/' 5 "http://yahoo.com/"
6 'http://bing.com/' 6 "http://bing.com/"
7 ] 7 ]
8 8
9 casper.start() 9 casper.start()
......
1 var casper = require("casper").create(); 1 var casper, links;
2 2
3 var links = [ 3 casper = require("casper").create();
4 'http://google.com/', 4
5 'http://yahoo.com/', 5 links = [
6 'http://bing.com/' 6 "http://google.com/",
7 "http://yahoo.com/",
8 "http://bing.com/"
7 ]; 9 ];
8 10
9 casper.start(); 11 casper.start();
10 12
11 casper.each(links, function(self, link) { 13 casper.each(links, function(self, link) {
12 this.thenOpen(link, function() { 14 this.thenOpen(link, function() {
13 this.echo((this.getTitle()) + " - " + link); 15 this.echo(this.getTitle() + " - " + link);
14 }); 16 });
15 }); 17 });
16 18
......
1 ###
2 This script will add a custom HTTP status code handler, here for 404 pages.
3 ###
4
1 casper = require("casper").create() 5 casper = require("casper").create()
2 6
3 casper.on "http.status.200", (resource) -> 7 casper.on "http.status.200", (resource) ->
...@@ -16,14 +20,15 @@ casper.on "http.status.500", (resource) -> ...@@ -16,14 +20,15 @@ casper.on "http.status.500", (resource) ->
16 @echo "#{resource.url} is in error", "ERROR" 20 @echo "#{resource.url} is in error", "ERROR"
17 21
18 links = [ 22 links = [
19 'http://google.com/' 23 "http://google.com/"
20 'http://www.google.com/' 24 "http://www.google.com/"
21 'http://www.google.com/plop' 25 "http://www.google.com/plop"
22 ] 26 ]
23 27
24 casper.start() 28 casper.start()
25 29
26 for link in links 30 casper.each links, (self, link) ->
27 casper.thenOpen link, -> @echo "#{link} loaded" 31 self.thenOpen link, ->
32 @echo "#{link} loaded"
28 33
29 casper.run() 34 casper.run()
......
1 /** 1 /*
2 * This script will add a custom HTTP status code handler, here for 404 pages. 2 This script will add a custom HTTP status code handler, here for 404 pages.
3 * 3 */
4 */ 4
5 var casper = require("casper").create(); 5 var casper, links;
6 6
7 casper.on('http.status.200', function(resource) { 7 casper = require("casper").create();
8 this.echo(resource.url + ' is OK', 'INFO'); 8
9 casper.on("http.status.200", function(resource) {
10 this.echo(resource.url + " is OK", "INFO");
9 }); 11 });
10 12
11 casper.on('http.status.301', function(resource) { 13 casper.on("http.status.301", function(resource) {
12 this.echo(resource.url + ' is permanently redirected', 'PARAMETER'); 14 this.echo(resource.url + " is permanently redirected", "PARAMETER");
13 }); 15 });
14 16
15 casper.on('http.status.302', function(resource) { 17 casper.on("http.status.302", function(resource) {
16 this.echo(resource.url + ' is temporarily redirected', 'PARAMETER'); 18 this.echo(resource.url + " is temporarily redirected", "PARAMETER");
17 }); 19 });
18 20
19 casper.on('http.status.404', function(resource) { 21 casper.on("http.status.404", function(resource) {
20 this.echo(resource.url + ' is not found', 'COMMENT'); 22 this.echo(resource.url + " is not found", "COMMENT");
21 }); 23 });
22 24
23 casper.on('http.status.500', function(resource) { 25 casper.on("http.status.500", function(resource) {
24 this.echo(resource.url + ' is in error', 'ERROR'); 26 this.echo(resource.url + " is in error", "ERROR");
25 }); 27 });
26 28
27 var links = [ 29 links = [
28 'http://google.com/', 30 "http://google.com/",
29 'http://www.google.com/', 31 "http://www.google.com/",
30 'http://www.google.com/plop' 32 "http://www.google.com/plop"
31 ]; 33 ];
32 34
33 casper.start().each(links, function(self, link) { 35 casper.start();
36
37 casper.each(links, function(self, link) {
34 self.thenOpen(link, function() { 38 self.thenOpen(link, function() {
35 this.echo(link + ' loaded'); 39 this.echo(link + " loaded");
36 }); 40 });
37 }); 41 });
38 42
......
1 casper = require("casper").create
2 loadImages: false
3 logLevel: "debug"
4 verbose: true
5
1 links = 6 links =
2 'http://edition.cnn.com/': 0 7 "http://edition.cnn.com/": 0
3 'http://www.nytimes.com/': 0 8 "http://www.nytimes.com/": 0
4 'http://www.bbc.co.uk/': 0 9 "http://www.bbc.co.uk/": 0
5 'http://www.guardian.co.uk/': 0 10 "http://www.guardian.co.uk/": 0
6 11
7 class Fantomas extends require("casper").Casper 12 fantomas = Object.create(casper)
8 countLinks: ->
9 @evaluate ->
10 __utils__.findAll('a').length
11 13
12 renderJSON: (what) -> 14 fantomas.countLinks = ->
13 @echo JSON.stringify what, null, ' ' 15 @evaluate ->
16 __utils__.findAll("a[href]").length
14 17
15 fantomas = new Fantomas 18 fantomas.renderJSON = (what) ->
16 loadImages: false 19 @echo JSON.stringify(what, null, " ")
17 logLevel: "debug"
18 verbose: true
19 20
20 fantomas.start() 21 fantomas.start()
21 22
22 for url of links 23 Object.keys(links).forEach (url) ->
23 do (url) -> 24 fantomas.thenOpen url, ->
24 fantomas.thenOpen url, -> 25 links[url] = @countLinks()
25 links[url] = @countLinks()
26 26
27 fantomas.run -> 27 fantomas.run ->
28 @renderJSON links 28 @renderJSON(links)
29 @exit() 29 @exit()
......
1 var casper = require("casper").create({ 1 var casper, fantomas, links;
2 loadImages: false, 2
3 casper = require("casper").create({
4 loadImages: false,
3 logLevel: "debug", 5 logLevel: "debug",
4 verbose: true 6 verbose: true
5 }); 7 });
6 8
7 var links = { 9 links = {
8 'http://edition.cnn.com/': 0, 10 "http://edition.cnn.com/": 0,
9 'http://www.nytimes.com/': 0, 11 "http://www.nytimes.com/": 0,
10 'http://www.bbc.co.uk/': 0, 12 "http://www.bbc.co.uk/": 0,
11 'http://www.guardian.co.uk/': 0 13 "http://www.guardian.co.uk/": 0
12 }; 14 };
13 15
14 var fantomas = Object.create(casper); 16 fantomas = Object.create(casper);
15 17
16 fantomas.countLinks = function(selector) { 18 fantomas.countLinks = function() {
17 return this.evaluate(function() { 19 return this.evaluate(function() {
18 return __utils__.findAll('a[href]').length; 20 return __utils__.findAll("a[href]").length;
19 }); 21 });
20 }; 22 };
21 23
22 fantomas.renderJSON = function(what) { 24 fantomas.renderJSON = function(what) {
23 return this.echo(JSON.stringify(what, null, ' ')); 25 this.echo(JSON.stringify(what, null, " "));
24 }; 26 };
25 27
26 fantomas.start(); 28 fantomas.start();
...@@ -32,5 +34,6 @@ Object.keys(links).forEach(function(url) { ...@@ -32,5 +34,6 @@ Object.keys(links).forEach(function(url) {
32 }); 34 });
33 35
34 fantomas.run(function() { 36 fantomas.run(function() {
35 this.renderJSON(links).exit(); 37 this.renderJSON(links);
36 }); 38 this.exit();
39 });
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -6,21 +6,21 @@ links = [] ...@@ -6,21 +6,21 @@ links = []
6 casper = require("casper").create() 6 casper = require("casper").create()
7 7
8 casper.start "http://google.fr/", -> 8 casper.start "http://google.fr/", ->
9 # search for 'casperjs' from google form 9 ### search for 'casperjs' from google form ###
10 @fill 'form[action="/search"]', q: "casperjs", true 10 @fill 'form[action="/search"]', q: "casperjs", true
11 11
12 casper.then -> 12 casper.then ->
13 # aggregate results for the 'casperjs' search 13 ### aggregate results for the 'casperjs' search ###
14 links = @evaluate getLinks 14 links = @evaluate getLinks
15 # search for 'phantomjs' from google form 15 ### search for 'phantomjs' from google form ###
16 @fill 'form[action="/search"]', q: "phantomjs", true 16 @fill 'form[action="/search"]', q: "phantomjs", true
17 17
18 casper.then -> 18 casper.then ->
19 # concat results for the 'phantomjs' search 19 ### concat results for the 'phantomjs' search ###
20 links = links.concat @evaluate(getLinks) 20 links = links.concat @evaluate(getLinks)
21 21
22 casper.run -> 22 casper.run ->
23 # display results 23 ### display results ###
24 @echo "#{links.length} links found:" 24 @echo "#{links.length} links found:"
25 @echo " - " + links.join "\n - " 25 @echo " - " + links.join "\n - "
26 @exit() 26 @exit()
......
1 var getLinks = function getLinks() { 1 var casper, getLinks, links;
2
3 getLinks = function() {
2 var links; 4 var links;
3 links = document.querySelectorAll("h3.r a"); 5 links = document.querySelectorAll("h3.r a");
4 return Array.prototype.map.call(links, function(e) { 6 return Array.prototype.map.call(links, function(e) {
...@@ -6,32 +8,33 @@ var getLinks = function getLinks() { ...@@ -6,32 +8,33 @@ var getLinks = function getLinks() {
6 }); 8 });
7 }; 9 };
8 10
9 var links = []; 11 links = [];
10 var casper = require("casper").create(); 12
13 casper = require("casper").create();
11 14
12 casper.start("http://google.fr/", function() { 15 casper.start("http://google.fr/", function() {
13 // search for 'casperjs' from google form 16 /* search for 'casperjs' from google form */
14 this.fill('form[action="/search"]', { 17 this.fill('form[action="/search"]', {
15 q: "casperjs" 18 q: "casperjs"
16 }, true); 19 }, true);
17 }); 20 });
18 21
19 casper.then(function() { 22 casper.then(function() {
20 // aggregate results for the 'casperjs' search 23 /* aggregate results for the 'casperjs' search */
21 links = this.evaluate(getLinks); 24 links = this.evaluate(getLinks);
22 // search for 'phantomjs' from google form 25 /* search for 'phantomjs' from google form */
23 this.fill('form[action="/search"]', { 26 this.fill('form[action="/search"]', {
24 q: "phantomjs" 27 q: "phantomjs"
25 }, true); 28 }, true);
26 }); 29 });
27 30
28 casper.then(function() { 31 casper.then(function() {
29 // concat results for the 'phantomjs' search 32 /* concat results for the 'phantomjs' search */
30 links = links.concat(this.evaluate(getLinks)); 33 links = links.concat(this.evaluate(getLinks));
31 }); 34 });
32 35
33 casper.run(function() { 36 casper.run(function() {
34 // display results 37 /* display results */
35 this.echo(links.length + " links found:"); 38 this.echo(links.length + " links found:");
36 this.echo(" - " + links.join("\n - ")); 39 this.echo(" - " + links.join("\n - "));
37 this.exit(); 40 this.exit();
......
...@@ -3,7 +3,7 @@ Takes provided terms passed as arguments and query google for the number of ...@@ -3,7 +3,7 @@ Takes provided terms passed as arguments and query google for the number of
3 estimated results each have. 3 estimated results each have.
4 4
5 Usage: 5 Usage:
6 $ casperjs googlematch.js nicolas chuck borris 6 $ casperjs googlematch.coffee nicolas chuck borris
7 nicolas: 69600000 7 nicolas: 69600000
8 chuck: 49500000 8 chuck: 49500000
9 borris: 2370000 9 borris: 2370000
......
...@@ -10,18 +10,21 @@ Usage: ...@@ -10,18 +10,21 @@ Usage:
10 winner is "nicolas" with 69600000 results 10 winner is "nicolas" with 69600000 results
11 */ 11 */
12 12
13 var casper = require("casper").create({ 13 var casper, scores, terms;
14
15 casper = require("casper").create({
14 verbose: true 16 verbose: true
15 }); 17 });
16 18
17 casper.fetchScore = function() { 19 casper.fetchScore = function() {
18 return this.evaluate(function() { 20 return this.evaluate(function() {
19 var result = document.querySelector('#resultStats').innerText; 21 var result;
22 result = document.querySelector('#resultStats').innerText;
20 return ~~(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, '')); 23 return ~~(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''));
21 }); 24 });
22 }; 25 };
23 26
24 var terms = casper.cli.args; 27 terms = casper.cli.args;
25 28
26 if (terms.length < 2) { 29 if (terms.length < 2) {
27 casper 30 casper
...@@ -30,7 +33,7 @@ if (terms.length < 2) { ...@@ -30,7 +33,7 @@ if (terms.length < 2) {
30 ; 33 ;
31 } 34 }
32 35
33 var scores = []; 36 scores = [];
34 37
35 casper.echo("Let the match begin between \"" + (terms.join('", "')) + "\"!"); 38 casper.echo("Let the match begin between \"" + (terms.join('", "')) + "\"!");
36 39
...@@ -54,10 +57,11 @@ casper.each(terms, function(self, term) { ...@@ -54,10 +57,11 @@ casper.each(terms, function(self, term) {
54 }); 57 });
55 58
56 casper.run(function() { 59 casper.run(function() {
60 var winner;
57 scores.sort(function(a, b) { 61 scores.sort(function(a, b) {
58 return b.score - a.score; 62 return b.score - a.score;
59 }); 63 });
60 var winner = scores[0]; 64 winner = scores[0];
61 this.echo("Winner is \"" + winner.term + "\" with " + winner.score + " results"); 65 this.echo("Winner is \"" + winner.term + "\" with " + winner.score + " results");
62 this.exit(); 66 this.exit();
63 }); 67 });
......
...@@ -24,16 +24,16 @@ processPage = -> ...@@ -24,16 +24,16 @@ processPage = ->
24 if @exists "#pnnext" 24 if @exists "#pnnext"
25 currentPage++ 25 currentPage++
26 @echo "requesting next page: #{currentPage}" 26 @echo "requesting next page: #{currentPage}"
27 #@thenClick("#pnnext").then(processPage)
28 url = @getCurrentUrl() 27 url = @getCurrentUrl()
29 @thenClick("#pnnext").then -> 28 @thenClick("#pnnext").then ->
30 check = -> url != @getCurrentUrl() 29 @waitFor (->
31 @waitFor check, processPage 30 url isnt @getCurrentUrl()
31 ), processPage
32 else 32 else
33 @echo "that's all, folks." 33 @echo "that's all, folks."
34 34
35 casper.start "http://google.fr/", -> 35 casper.start "http://google.fr/", ->
36 @fill 'form[action="/search"]', q: casper.cli.args.join(' '), true 36 @fill 'form[action="/search"]', q: casper.cli.args.join(" "), true
37 37
38 casper.then processPage 38 casper.then processPage
39 39
......
...@@ -6,18 +6,19 @@ Usage: $ casperjs googlepagination.coffee my search terms ...@@ -6,18 +6,19 @@ Usage: $ casperjs googlepagination.coffee my search terms
6 (all arguments will be used as the query) 6 (all arguments will be used as the query)
7 */ 7 */
8 8
9 var casper = require("casper").create(); 9 var casper, currentPage, processPage;
10 10
11 var currentPage = 1; 11 casper = require("casper").create();
12 currentPage = 1;
12 13
13 if (casper.cli.args.length === 0) { 14 if (casper.cli.args.length === 0) {
14 casper 15 casper
15 .echo("Usage: $ casperjs googlepagination.coffee my search terms") 16 .echo("Usage: $ casperjs googlepagination.js my search terms")
16 .exit(1) 17 .exit(1)
17 ; 18 ;
18 } 19 }
19 20
20 var processPage = function processPage() { 21 processPage = function() {
21 var url; 22 var url;
22 this.echo("capturing page " + currentPage); 23 this.echo("capturing page " + currentPage);
23 this.capture("google-results-p" + currentPage + ".png"); 24 this.capture("google-results-p" + currentPage + ".png");
...@@ -28,8 +29,8 @@ var processPage = function processPage() { ...@@ -28,8 +29,8 @@ var processPage = function processPage() {
28 currentPage++; 29 currentPage++;
29 this.echo("requesting next page: " + currentPage); 30 this.echo("requesting next page: " + currentPage);
30 url = this.getCurrentUrl(); 31 url = this.getCurrentUrl();
31 return this.thenClick("#pnnext").then(function() { 32 this.thenClick("#pnnext").then(function() {
32 return this.waitFor(function() { 33 this.waitFor(function() {
33 return url !== this.getCurrentUrl(); 34 return url !== this.getCurrentUrl();
34 }, processPage); 35 }, processPage);
35 }); 36 });
...@@ -39,8 +40,8 @@ var processPage = function processPage() { ...@@ -39,8 +40,8 @@ var processPage = function processPage() {
39 }; 40 };
40 41
41 casper.start("http://google.fr/", function() { 42 casper.start("http://google.fr/", function() {
42 return this.fill('form[action="/search"]', { 43 this.fill('form[action="/search"]', {
43 q: casper.cli.args.join(' ') 44 q: casper.cli.args.join(" ")
44 }, true); 45 }, true);
45 }); 46 });
46 47
......
1 casper = require("casper").create logLevel: "debug" 1 casper = require("casper").create
2 logLevel: "debug"
2 3
3 casper.start "http://www.google.fr/", -> 4 casper.start "http://www.google.fr/", ->
4 @test.assertTitle 'Google', 'google homepage title is the one expected' 5 @test.assertTitle "Google", "google homepage title is the one expected"
5 @test.assertExists 'form[action="/search"]', 'main form is found' 6 @test.assertExists 'form[action="/search"]', "main form is found"
6 @fill 'form[action="/search"]', q: 'foo', true 7 @fill 'form[action="/search"]', q: "foo", true
7 8
8 casper.then -> 9 casper.then ->
9 @test.assertTitle 'foo - Recherche Google', 'google title is ok' 10 @test.assertTitle "foo - Recherche Google", "google title is ok"
10 @test.assertUrlMatch /q=foo/, 'search term has been submitted' 11 @test.assertUrlMatch /q=foo/, "search term has been submitted"
11 test = -> __utils__.findAll('h3.r').length >= 10 12 @test.assertEval (->
12 @test.assertEval test, 'google search for "foo" retrieves 10 or more results' 13 __utils__.findAll("h3.r").length >= 10
14 ), "google search for \"foo\" retrieves 10 or more results"
13 15
14 casper.run -> @test.renderResults true 16 casper.run ->
17 @test.renderResults true
......
1 var casper = require("casper").create({ 1 var casper;
2
3 casper = require("casper").create({
2 logLevel: "debug" 4 logLevel: "debug"
3 }); 5 });
4 6
5 casper.start("http://www.google.fr/", function(self) { 7 casper.start("http://www.google.fr/", function() {
6 self.test.assertTitle('Google', 'google homepage title is the one expected'); 8 this.test.assertTitle("Google", "google homepage title is the one expected");
7 self.test.assertExists('form[action="/search"]', 'main form is found'); 9 this.test.assertExists('form[action="/search"]', "main form is found");
8 self.fill('form[action="/search"]', { 10 this.fill('form[action="/search"]', {
9 q: 'foo' 11 q: "foo"
10 }, true); 12 }, true);
11 }); 13 });
12 14
13 casper.then(function(self) { 15 casper.then(function() {
14 self.test.assertTitle('foo - Recherche Google', 'google title is ok'); 16 this.test.assertTitle("foo - Recherche Google", "google title is ok");
15 self.test.assertUrlMatch(/q=foo/, 'search term has been submitted'); 17 this.test.assertUrlMatch(/q=foo/, "search term has been submitted");
16 self.test.assertEval(function() { 18 this.test.assertEval((function() {
17 return __utils__.findAll('h3.r').length >= 10; 19 return __utils__.findAll("h3.r").length >= 10;
18 }, 'google search for "foo" retrieves 10 or more results'); 20 }), "google search for \"foo\" retrieves 10 or more results");
19 }); 21 });
20 22
21 casper.run(function(self) { 23 casper.run(function() {
22 self.test.renderResults(true); 24 this.test.renderResults(true);
23 }); 25 });
......
1 casper = require("casper").create 1 casper = require("casper").create
2 verbose: true 2 verbose: true
3 logLevel: 'debug' 3 logLevel: "debug"
4 4
5 casper.log "this is a debug message", 'debug' 5 casper.log "this is a debug message", "debug"
6 casper.log "and an informative one", 'info' 6 casper.log "and an informative one", "info"
7 casper.log "and a warning", 'warning' 7 casper.log "and a warning", "warning"
8 casper.log "and an error", 'error' 8 casper.log "and an error", "error"
9 9
10 casper.exit() 10 casper.exit()
......
1 var casper = require("casper").create({ 1 var casper;
2
3 casper = require("casper").create({
2 verbose: true, 4 verbose: true,
3 logLevel: 'debug' 5 logLevel: "debug"
4 }); 6 });
5 7
6 casper.log("this is a debug message", 'debug'); 8 casper.log("this is a debug message", "debug");
7 casper.log("and an informative one", 'info'); 9 casper.log("and an informative one", "info");
8 casper.log("and a warning", 'warning'); 10 casper.log("and a warning", "warning");
9 casper.log("and an error", 'error'); 11 casper.log("and an error", "error");
10 12
11 casper.exit(); 13 casper.exit();
......
...@@ -4,8 +4,8 @@ metas = [] ...@@ -4,8 +4,8 @@ metas = []
4 4
5 if not url 5 if not url
6 casper 6 casper
7 .echo "Usage: casperjs [url]" 7 .echo("Usage: $ casperjs metaextract.coffee <url>")
8 .exit(1) 8 .exit 1
9 9
10 casper.start url, -> 10 casper.start url, ->
11 metas = @evaluate -> 11 metas = @evaluate ->
......
1 var casper = require("casper").create() 1 var casper, metas, url;
2 , url = casper.cli.get(0) 2
3 , metas = []; 3 casper = require("casper").create();
4 url = casper.cli.get(0);
5 metas = [];
4 6
5 if (!url) { 7 if (!url) {
6 casper 8 casper
7 .echo("Usage: casperjs [url]") 9 .echo("Usage: $ casperjs metaextract.js <url>")
8 .exit(1) 10 .exit(1)
9 ; 11 ;
10 } 12 }
...@@ -12,7 +14,7 @@ if (!url) { ...@@ -12,7 +14,7 @@ if (!url) {
12 casper.start(url, function() { 14 casper.start(url, function() {
13 metas = this.evaluate(function() { 15 metas = this.evaluate(function() {
14 var metas = []; 16 var metas = [];
15 [].forEach.call(document.querySelectorAll('meta'), function(elem) { 17 [].forEach.call(document.querySelectorAll("meta"), function(elem) {
16 var meta = {}; 18 var meta = {};
17 [].slice.call(elem.attributes).forEach(function(attr) { 19 [].slice.call(elem.attributes).forEach(function(attr) {
18 meta[attr.name] = attr.value; 20 meta[attr.name] = attr.value;
......
1 var casper = require("casper").create({ 1 var casper, check, countLinks, currentSuite, suites;
2
3 casper = require("casper").create({
2 verbose: true 4 verbose: true
3 }); 5 });
4 6
5 var countLinks = function countLinks() { 7 countLinks = function() {
6 return document.querySelectorAll('a').length; 8 return document.querySelectorAll('a').length;
7 }; 9 };
8 10
9 var suites = [ 11 suites = [
10 function() { 12 function() {
11 this.echo("Suite 1"); 13 this.echo("Suite 1");
12 this.start("http://google.com/", function() { 14 this.start("http://google.com/", function() {
...@@ -40,9 +42,9 @@ casper.then(function() { ...@@ -40,9 +42,9 @@ casper.then(function() {
40 this.echo("Starting"); 42 this.echo("Starting");
41 }); 43 });
42 44
43 var currentSuite = 0; 45 currentSuite = 0;
44 46
45 var check = function check() { 47 check = function() {
46 if (suites[currentSuite]) { 48 if (suites[currentSuite]) {
47 suites[currentSuite].call(this); 49 suites[currentSuite].call(this);
48 currentSuite++; 50 currentSuite++;
......
...@@ -17,9 +17,12 @@ if not twitterAccount or not filename or not /\.(png|jpg|pdf)$/i.test filename ...@@ -17,9 +17,12 @@ if not twitterAccount or not filename or not /\.(png|jpg|pdf)$/i.test filename
17 .exit(1) 17 .exit(1)
18 18
19 casper.start "https://twitter.com/#!/#{twitterAccount}", -> 19 casper.start "https://twitter.com/#!/#{twitterAccount}", ->
20 capture = -> 20 @waitForSelector ".tweet-row", (->
21 @captureSelector filename, 'html' 21 @captureSelector filename, "html"
22 @echo "Saved screenshot of #{@getCurrentUrl()} to #{filename}" 22 @echo "Saved screenshot of #{@getCurrentUrl()} to #{filename}"
23 @waitForSelector '.tweet-row', capture, null, 12000 23 ), (->
24 @die("Timeout reached. Fail whale?")
25 @exit()
26 ), 12000
24 27
25 casper.run() 28 casper.run()
......
...@@ -3,15 +3,17 @@ This script will capture a screenshot of a twitter account page ...@@ -3,15 +3,17 @@ This script will capture a screenshot of a twitter account page
3 Usage: $ casperjs screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]> 3 Usage: $ casperjs screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>
4 */ 4 */
5 5
6 var casper = require("casper").create({ 6 var casper, filename, twitterAccount;
7
8 casper = require("casper").create({
7 viewportSize: { 9 viewportSize: {
8 width: 1024, 10 width: 1024,
9 height: 768 11 height: 768
10 } 12 }
11 }); 13 });
12 14
13 var twitterAccount = casper.cli.get(0); 15 twitterAccount = casper.cli.get(0);
14 var filename = casper.cli.get(1); 16 filename = casper.cli.get(1);
15 17
16 if (!twitterAccount || !filename || !/\.(png|jpg|pdf)$/i.test(filename)) { 18 if (!twitterAccount || !filename || !/\.(png|jpg|pdf)$/i.test(filename)) {
17 casper 19 casper
...@@ -21,12 +23,13 @@ if (!twitterAccount || !filename || !/\.(png|jpg|pdf)$/i.test(filename)) { ...@@ -21,12 +23,13 @@ if (!twitterAccount || !filename || !/\.(png|jpg|pdf)$/i.test(filename)) {
21 } 23 }
22 24
23 casper.start("https://twitter.com/#!/" + twitterAccount, function() { 25 casper.start("https://twitter.com/#!/" + twitterAccount, function() {
24 this.waitForSelector('.tweet-row', function() { 26 this.waitForSelector(".tweet-row", (function() {
25 this.captureSelector(filename, 'html'); 27 this.captureSelector(filename, "html");
26 this.echo("Saved screenshot of " + this.getCurrentUrl() + " to " + filename); 28 this.echo("Saved screenshot of " + (this.getCurrentUrl()) + " to " + filename);
27 }, function() { 29 }), (function() {
28 this.die('Timeout reached. Fail whale?').exit(); 30 this.die("Timeout reached. Fail whale?");
29 }, 12000); 31 this.exit();
32 }), 12000);
30 }); 33 });
31 34
32 casper.run(); 35 casper.run();
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
2 This script will add a custom HTTP status code handler, here for 404 pages. 2 This script will add a custom HTTP status code handler, here for 404 pages.
3 */ 3 */
4 4
5 var casper = require("casper").create({ 5 var casper;
6
7 casper = require("casper").create({
6 httpStatusHandlers: { 8 httpStatusHandlers: {
7 404: function(self, resource) { 9 404: function(self, resource) {
8 this.echo("Resource at " + resource.url + " not found (404)", "COMMENT"); 10 this.echo("Resource at " + resource.url + " not found (404)", "COMMENT");
......
1 var failed = []; 1 var casper, failed, links, timeout,
2 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
2 3
3 var casper = require("casper").create({ 4 failed = [];
5
6 casper = require("casper").create({
4 onStepTimeout: function() { 7 onStepTimeout: function() {
5 failed.push(this.requestUrl); 8 failed.push(this.requestUrl);
6 } 9 }
7 }); 10 });
8 11
9 var links = [ 12 links = [
10 'http://google.com/', 13 'http://google.com/',
11 'http://akei.com/', 14 'http://akei.com/',
12 'http://lemonde.fr/', 15 'http://lemonde.fr/',
...@@ -14,10 +17,12 @@ var links = [ ...@@ -14,10 +17,12 @@ var links = [
14 'http://cdiscount.fr/' 17 'http://cdiscount.fr/'
15 ]; 18 ];
16 19
17 var timeout = ~~casper.cli.get(0); 20 timeout = ~~casper.cli.get(0);
21
18 if (timeout < 1) { 22 if (timeout < 1) {
19 timeout = 1000; 23 timeout = 1000;
20 } 24 }
25
21 casper.options.stepTimeout = timeout; 26 casper.options.stepTimeout = timeout;
22 27
23 casper.echo("Testing with timeout=" + casper.options.stepTimeout + "ms."); 28 casper.echo("Testing with timeout=" + casper.options.stepTimeout + "ms.");
...@@ -25,13 +30,13 @@ casper.echo("Testing with timeout=" + casper.options.stepTimeout + "ms."); ...@@ -25,13 +30,13 @@ casper.echo("Testing with timeout=" + casper.options.stepTimeout + "ms.");
25 casper.start(); 30 casper.start();
26 31
27 casper.each(links, function(self, link) { 32 casper.each(links, function(self, link) {
28 self.test.comment('Adding ' + link + ' to test suite'); 33 this.test.comment("Adding " + link + " to test suite");
29 self.thenOpen(link, function(self) { 34 this.thenOpen(link, function() {
30 var testStatus = self.test.pass; 35 var _ref;
31 if (failed.indexOf(self.requestUrl) > -1) { 36 if (_ref = this.requestUrl, __indexOf.call(failed, _ref) >= 0) {
32 self.test.fail(self.requestUrl); 37 this.test.fail("" + this.requestUrl + " loaded in less than " + timeout + "ms.");
33 } else { 38 } else {
34 self.test.pass(self.requestUrl); 39 this.test.pass("" + this.requestUrl + " loaded in less than " + timeout + "ms.");
35 } 40 }
36 }); 41 });
37 }); 42 });
......
...@@ -17,7 +17,7 @@ YES! ...@@ -17,7 +17,7 @@ YES!
17 17
18 casper = require("casper").create 18 casper = require("casper").create
19 onTimeout: -> 19 onTimeout: ->
20 @echo "NOPE.", 'RED_BAR' 20 @echo "NOPE.", "RED_BAR"
21 @exit() 21 @exit()
22 22
23 timeout = ~~casper.cli.get 0 23 timeout = ~~casper.cli.get 0
...@@ -30,7 +30,7 @@ casper.echo "Will google.com load in less than #{timeout}ms?" ...@@ -30,7 +30,7 @@ casper.echo "Will google.com load in less than #{timeout}ms?"
30 casper.options.timeout = timeout 30 casper.options.timeout = timeout
31 31
32 casper.start "http://www.google.com/", -> 32 casper.start "http://www.google.com/", ->
33 @echo "YES!", 'GREEN_BAR' 33 @echo "YES!", "GREEN_BAR"
34 @exit() 34 @exit()
35 35
36 casper.run() 36 casper.run()
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,16 +15,18 @@ Will google.com load in less than 2000ms? ...@@ -15,16 +15,18 @@ Will google.com load in less than 2000ms?
15 YES! 15 YES!
16 */ 16 */
17 17
18 var casper = require("casper").create({ 18 var casper, timeout;
19
20 casper = require("casper").create({
19 onTimeout: function() { 21 onTimeout: function() {
20 this 22 this
21 .echo("NOPE.", 'RED_BAR') 23 .echo("NOPE.", "RED_BAR")
22 .exit() 24 .exit()
23 ; 25 ;
24 } 26 }
25 }); 27 });
26 28
27 var timeout = ~~casper.cli.get(0); 29 timeout = ~~casper.cli.get(0);
28 30
29 if (timeout < 1) { 31 if (timeout < 1) {
30 casper 32 casper
...@@ -32,14 +34,13 @@ if (timeout < 1) { ...@@ -32,14 +34,13 @@ if (timeout < 1) {
32 .exit(1) 34 .exit(1)
33 ; 35 ;
34 } 36 }
37
35 casper.echo("Will google.com load in less than " + timeout + "ms?"); 38 casper.echo("Will google.com load in less than " + timeout + "ms?");
36 casper.options.timeout = timeout; 39 casper.options.timeout = timeout;
37 40
38 casper.start("http://www.google.com/", function() { 41 casper.start("http://www.google.com/", function() {
39 this 42 this.echo("YES!", 'GREEN_BAR');
40 .echo("YES!", 'GREEN_BAR') 43 this.exit();
41 .exit()
42 ;
43 }); 44 });
44 45
45 casper.run(); 46 casper.run();
......