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) { ...@@ -2094,6 +2094,11 @@ function createPage(casper) {
2094 casper.log(msg, logLevel, "remote"); 2094 casper.log(msg, logLevel, "remote");
2095 casper.emit('remote.message', msg); 2095 casper.emit('remote.message', msg);
2096 }; 2096 };
2097
2098 page.onCallback = function onCallback(data){
2099 casper.emit('remote.callback',data);
2100 };
2101
2097 page.onError = function onError(msg, trace) { 2102 page.onError = function onError(msg, trace) {
2098 casper.emit('page.error', msg, trace); 2103 casper.emit('page.error', msg, trace);
2099 }; 2104 };
......
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS test callback</title>
6 </head>
7 <body>
8 <script>window.callPhantom({"hello":"world"})</script>
9 </body>
10 </html>
1 /*global casper*/
2 /*jshint strict:false*/
3 casper.test.begin('callback events', 1, {
4 ok: false,
5
6 tearDown: function(test) {
7 casper.removeAllListeners('remote.callback');
8 },
9
10 test: function(test) {
11 var self = this;
12
13 casper.once('remote.callback', function(data) {
14 self.ok = (data.hello === 'world');
15 });
16
17 casper.start('tests/site/callback.html', function() {
18 test.assert(self.ok, 'callback event has been intercepted');
19 });
20
21 casper.run(function() {
22 test.done();
23 });
24 }
25 });