Commit 4359c1c6 4359c1c6e5417605069bb00425fb04422630622f by Nicolas Perriault

Merge pull request #409 from nabriski/callback

refs #408 - added support for PhantomJS onCallback (window.callPhantom)
2 parents 0efe5bf5 759ec0ce
......@@ -2180,6 +2180,11 @@ function createPage(casper) {
casper.log(msg, logLevel, "remote");
casper.emit('remote.message', msg);
};
page.onCallback = function onCallback(data){
casper.emit('remote.callback',data);
};
page.onError = function onError(msg, trace) {
casper.emit('page.error', msg, trace);
};
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS test callback</title>
</head>
<body>
<script>window.callPhantom({"hello":"world"})</script>
</body>
</html>
/*global casper*/
/*jshint strict:false*/
casper.test.begin('callback events', 1, {
ok: false,
tearDown: function(test) {
casper.removeAllListeners('remote.callback');
},
test: function(test) {
var self = this;
casper.once('remote.callback', function(data) {
self.ok = (data.hello === 'world');
});
casper.start('tests/site/callback.html', function() {
test.assert(self.ok, 'callback event has been intercepted');
});
casper.run(function() {
test.done();
});
}
});