Commit 58c04d05 58c04d05ec1bdcd7ef18f55bd64d7c2f1cf31d23 by Nicolas Perriault

added ClientUtils.echo()

To print stuff out to the casper console from the remote page DOM environment:

```javascript
casper.start('http://foo.ner/').thenEvaluate(function() {
    __utils__.echo('plop'); // this will be printed to your shell at runtime
});
```
1 parent 7d0b40a5
......@@ -1782,10 +1782,18 @@ function createPage(casper) {
return casper.filter('page.confirm', message) || true;
};
page.onConsoleMessage = function onConsoleMessage(msg) {
var level = "info", test = /^\[casper:(\w+)\]\s?(.*)/.exec(msg);
if (test && test.length === 3) {
level = test[1];
msg = test[2];
// client utils log messages
var level = "info", logTest = /^\[casper:(\w+)\]\s?(.*)/.exec(msg);
if (logTest && logTest.length === 3) {
level = logTest[1];
msg = logTest[2];
return; // don't trigger remote.message event for these
}
// client utils casper console message
var consoleTest = /^\[casper\.echo\]\s?(.*)/.exec(msg);
if (consoleTest && consoleTest.length === 2) {
casper.echo(consoleTest[1]);
return; // don't trigger remote.message event for these
}
casper.log(msg, level, "remote");
casper.emit('remote.message', msg);
......
......@@ -117,6 +117,16 @@
};
/**
* Echoes something to casper console.
*
* @param String message
* @return
*/
this.echo = function echo(message) {
console.log("[casper.echo] " + message);
};
/**
* Base64 encodes a string, even binary ones. Succeeds where
* window.btoa() fails.
*
......