Commit 759ec0ce 759ec0ce8576f1ff47b34af040c88796a9fb3a0d by Itamar Nabriski

refs #408 - added support for PhantomJS onCallback (window.callPhantom)

1 parent 64b73b49
......@@ -2094,6 +2094,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();
});
}
});