forked from casperjs/casperjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
373 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
casper = require("casper").create() | ||
|
||
# listening to a custom event | ||
casper.on 'google.loaded', (title) -> | ||
### listening to a custom event ### | ||
casper.on "google.loaded", (title) -> | ||
casper.echo "Google page title is #{title}" | ||
|
||
casper.start "http://google.com/", -> | ||
# emitting a custom event | ||
@emit 'google.loaded', @getTitle() | ||
### emitting a custom event ### | ||
@emit "google.loaded", @getTitle() | ||
|
||
casper.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
var casper = require("casper").create(); | ||
var casper; | ||
|
||
// listening to a custom event | ||
casper.on('google.loaded', function(title) { | ||
casper = require("casper").create(); | ||
|
||
/* listening to a custom event */ | ||
casper.on("google.loaded", function(title) { | ||
casper.echo("Google page title is " + title); | ||
}); | ||
|
||
casper.start("http://google.com/", function() { | ||
// emitting a custom event | ||
this.emit('google.loaded', this.getTitle()); | ||
/* emitting a custom event */ | ||
this.emit("google.loaded", this.getTitle()); | ||
}); | ||
|
||
casper.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
### | ||
A basic custom logging implementation. The idea is to (extremely) verbosely | ||
log every received resource. | ||
A basic custom logging implementation. The idea is to (extremely) verbosely log | ||
every received resource. | ||
### | ||
|
||
casper = require("casper").create | ||
# Every time a resource is received, a new log entry is added to the stack | ||
# at the 'verbose' level. | ||
### | ||
Every time a resource is received, a new log entry is added to the stack at | ||
the 'verbose' level. | ||
### | ||
onResourceReceived: (self, resource) -> | ||
infos = [] | ||
props = ["url", "status", "statusText", "redirectURL", "bodySize"] | ||
props = [ | ||
"url" | ||
"status" | ||
"statusText" | ||
"redirectURL" | ||
"bodySize" | ||
] | ||
infos.push resource[prop] for prop in props | ||
infos.push "[#{h.name}: #{h.value}]" for h in resource.headers | ||
@log infos.join(', '), 'verbose' | ||
infos.push "[#{header.name}: #{header.value}]" for header in resource.headers | ||
@log infos.join(", "), "verbose" | ||
verbose: true # we want to see the log printed out to the console | ||
logLevel: 'verbose' # of course we want to see logs to our new level :) | ||
logLevel: "verbose" # of course we want to see logs to our new level :) | ||
|
||
### add a new 'verbose' logging level at the lowest priority ### | ||
casper.logLevels = ["verbose"].concat casper.logLevels | ||
|
||
# add a new 'verbose' logging level at the lowest priority | ||
casper.logLevels = ['verbose'].concat casper.logLevels | ||
|
||
# test our new logger with google | ||
### test our new logger with google ### | ||
casper.start "http://www.google.com/" | ||
casper.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,44 @@ | ||
/* | ||
A basic custom logging implementation. The idea is to (extremely) verbosely | ||
log every received resource. | ||
A basic custom logging implementation. The idea is to (extremely) verbosely log | ||
every received resource. | ||
*/ | ||
|
||
var casper = require("casper").create({ | ||
/** | ||
* Every time a resource is received, a new log entry is added to the stack | ||
* at the 'verbose' level. | ||
* | ||
* @param Object resource A phantomjs resource object | ||
*/ | ||
var casper; | ||
|
||
casper = require("casper").create({ | ||
/* | ||
Every time a resource is received, a new log entry is added to the stack at | ||
the 'verbose' level. | ||
*/ | ||
onResourceReceived: function(self, resource) { | ||
var infos = [ | ||
resource.url, | ||
resource.status, | ||
resource.statusText, | ||
resource.redirectURL, | ||
resource.bodySize | ||
var header, infos, prop, props, _i, _j, _len, _len1, _ref; | ||
infos = []; | ||
props = [ | ||
"url", | ||
"status", | ||
"statusText", | ||
"redirectURL", | ||
"bodySize" | ||
]; | ||
resource.headers.forEach(function(header) { | ||
infos.push('[' + [header.name, header.value].join(', ') + ']'); | ||
}); | ||
self.log(infos.join(', '), 'verbose'); | ||
for (_i = 0, _len = props.length; _i < _len; _i++) { | ||
prop = props[_i]; | ||
infos.push(resource[prop]); | ||
} | ||
_ref = resource.headers; | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
header = _ref[_j]; | ||
infos.push("[" + header.name + ": " + header.value + "]"); | ||
} | ||
this.log(infos.join(", "), "verbose"); | ||
}, | ||
verbose: true, // we want to see the log printed out to the console | ||
logLevel: 'verbose' // of course we want to see logs to our new level :) | ||
verbose: true, | ||
logLevel: "verbose" | ||
}); | ||
|
||
// add a new 'verbose' logging level at the lowest priority | ||
casper.logLevels = ['verbose'].concat(casper.logLevels); | ||
/* add a new 'verbose' logging level at the lowest priority */ | ||
casper.logLevels = ["verbose"].concat(casper.logLevels); | ||
|
||
// test our new logger with google | ||
casper.start("http://www.google.com/").run(function(self) { | ||
self.exit(); | ||
}); | ||
/* test our new logger with google */ | ||
casper.start("http://www.google.com/"); | ||
|
||
casper.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.