Commit 0cef17ee 0cef17eea509dd23ee8e70ba53fd97bca427672f by Nicolas Perriault

fixes #325

1 parent 19d0f4c2
...@@ -21,15 +21,16 @@ casper.start "http://www.bbc.co.uk/", -> ...@@ -21,15 +21,16 @@ casper.start "http://www.bbc.co.uk/", ->
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"
24 @waitUntilVisible ".autoplay.nav_pause", -> 24
25 @echo "Moving over pause button" 25 casper.waitUntilVisible ".autoplay.nav_pause", ->
26 @mouse.move ".autoplay.nav_pause" 26 @echo "Moving over pause button"
27 @click ".autoplay.nav_pause" 27 @mouse.move ".autoplay.nav_pause"
28 @echo "Clicked on pause button" 28 @click ".autoplay.nav_pause"
29 @waitUntilVisible ".autoplay.nav_play", -> 29 @echo "Clicked on pause button"
30 @echo "Carousel has been paused" 30 @waitUntilVisible ".autoplay.nav_play", ->
31 # hide play button 31 @echo "Carousel has been paused"
32 @hide ".autoplay" 32 # hide play button
33 @hide ".autoplay"
33 34
34 # Capture carrousel area 35 # Capture carrousel area
35 next = -> 36 next = ->
......
...@@ -28,16 +28,17 @@ casper.start("http://www.bbc.co.uk/", function() { ...@@ -28,16 +28,17 @@ casper.start("http://www.bbc.co.uk/", function() {
28 this.hide(".nav_left"); 28 this.hide(".nav_left");
29 this.hide(".nav_right"); 29 this.hide(".nav_right");
30 this.mouse.move("#promo2_carousel"); 30 this.mouse.move("#promo2_carousel");
31 this.waitUntilVisible(".autoplay.nav_pause", function() { 31 });
32 this.echo("Moving over pause button"); 32
33 this.mouse.move(".autoplay.nav_pause"); 33 casper.waitUntilVisible(".autoplay.nav_pause", function() {
34 this.click(".autoplay.nav_pause"); 34 this.echo("Moving over pause button");
35 this.echo("Clicked on pause button"); 35 this.mouse.move(".autoplay.nav_pause");
36 this.waitUntilVisible(".autoplay.nav_play", function() { 36 this.click(".autoplay.nav_pause");
37 this.echo("Carousel has been paused"); 37 this.echo("Clicked on pause button");
38 // hide play button 38 this.waitUntilVisible(".autoplay.nav_play", function() {
39 this.hide(".autoplay"); 39 this.echo("Carousel has been paused");
40 }); 40 // hide play button
41 this.hide(".autoplay");
41 }); 42 });
42 }); 43 });
43 44
......
...@@ -2,29 +2,27 @@ ...@@ -2,29 +2,27 @@
2 A basic custom logging implementation. The idea is to (extremely) verbosely 2 A basic custom logging implementation. The idea is to (extremely) verbosely
3 log every received resource. 3 log every received resource.
4 ### 4 ###
5
6 casper = require("casper").create 5 casper = require("casper").create
7 ###
8 Every time a resource is received, a new log entry is added to the stack
9 at the 'verbose' level.
10
11 @param Object resource A phantomjs resource object
12 ###
13 onResourceReceived: (self, resource) ->
14 infos = []
15 props = [
16 "url"
17 "status"
18 "statusText"
19 "redirectURL"
20 "bodySize"
21 ]
22 infos.push resource[prop] for prop in props
23 infos.push "[#{header.name}: #{header.value}]" for header in resource.headers
24 @log infos.join(", "), "verbose"
25 verbose: true # we want to see the log printed out to the console 6 verbose: true # we want to see the log printed out to the console
26 logLevel: "verbose" # of course we want to see logs to our new level :) 7 logLevel: "verbose" # of course we want to see logs to our new level :)
27 8
9 ###
10 Every time a resource is received, a new log entry is added to the stack
11 at the 'verbose' level.
12 ###
13 casper.on 'resource.received', (resource) ->
14 infos = []
15 props = [
16 "url"
17 "status"
18 "statusText"
19 "redirectURL"
20 "bodySize"
21 ]
22 infos.push resource[prop] for prop in props
23 infos.push "[#{header.name}: #{header.value}]" for header in resource.headers
24 @log infos.join(", "), "verbose"
25
28 # add a new 'verbose' logging level at the lowest priority 26 # add a new 'verbose' logging level at the lowest priority
29 casper.logLevels = ["verbose"].concat casper.logLevels 27 casper.logLevels = ["verbose"].concat casper.logLevels
30 28
......
...@@ -5,37 +5,33 @@ ...@@ -5,37 +5,33 @@
5 * A basic custom logging implementation. The idea is to (extremely) verbosely 5 * A basic custom logging implementation. The idea is to (extremely) verbosely
6 * log every received resource. 6 * log every received resource.
7 */ 7 */
8
9 var casper = require("casper").create({ 8 var casper = require("casper").create({
10 /*
11 Every time a resource is received, a new log entry is added to the stack at
12 the 'verbose' level.
13 */
14 onResourceReceived: function(self, resource) {
15 var header, infos, prop, props, _i, _j, _len, _len1, _ref;
16 infos = [];
17 props = [
18 "url",
19 "status",
20 "statusText",
21 "redirectURL",
22 "bodySize"
23 ];
24 for (_i = 0, _len = props.length; _i < _len; _i++) {
25 prop = props[_i];
26 infos.push(resource[prop]);
27 }
28 _ref = resource.headers;
29 for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
30 header = _ref[_j];
31 infos.push("[" + header.name + ": " + header.value + "]");
32 }
33 this.log(infos.join(", "), "verbose");
34 },
35 verbose: true, 9 verbose: true,
36 logLevel: "verbose" 10 logLevel: "verbose"
37 }); 11 });
38 12
13 /**
14 * Every time a resource is received, a new log entry is added to the stack at
15 * the 'verbose' level.
16 */
17 casper.on('resource.received', function(resource) {
18 var infos = [];
19 var props = [
20 "url",
21 "status",
22 "statusText",
23 "redirectURL",
24 "bodySize"
25 ];
26 props.forEach(function(prop) {
27 infos.push(resource[prop]);
28 });
29 resource.headers.forEach(function(header) {
30 infos.push("[" + header.name + ": " + header.value + "]");
31 });
32 this.log(infos.join(", "), "verbose");
33 });
34
39 // add a new 'verbose' logging level at the lowest priority 35 // add a new 'verbose' logging level at the lowest priority
40 casper.logLevels = ["verbose"].concat(casper.logLevels); 36 casper.logLevels = ["verbose"].concat(casper.logLevels);
41 37
......
...@@ -14,7 +14,7 @@ casper = require("casper").create verbose: true ...@@ -14,7 +14,7 @@ casper = require("casper").create verbose: true
14 14
15 casper.fetchScore = -> 15 casper.fetchScore = ->
16 @evaluate -> 16 @evaluate ->
17 result = document.querySelector('#resultStats').innerText 17 result = __utils__.findOne('#resultStats').innerText
18 parseInt /Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, '') 18 parseInt /Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, '')
19 19
20 terms = casper.cli.args # terms are passed through command-line arguments 20 terms = casper.cli.args # terms are passed through command-line arguments
......
...@@ -19,7 +19,7 @@ var casper = require("casper").create({ ...@@ -19,7 +19,7 @@ var casper = require("casper").create({
19 19
20 casper.fetchScore = function() { 20 casper.fetchScore = function() {
21 return this.evaluate(function() { 21 return this.evaluate(function() {
22 var result = document.querySelector('#resultStats').innerText; 22 var result = __utils__.findOne('#resultStats').innerText;
23 return parseInt(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''), 10); 23 return parseInt(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''), 10);
24 }); 24 });
25 }; 25 };
......