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) { ...@@ -2180,6 +2180,11 @@ function createPage(casper) {
2180 casper.log(msg, logLevel, "remote"); 2180 casper.log(msg, logLevel, "remote");
2181 casper.emit('remote.message', msg); 2181 casper.emit('remote.message', msg);
2182 }; 2182 };
2183
2184 page.onCallback = function onCallback(data){
2185 casper.emit('remote.callback',data);
2186 };
2187
2183 page.onError = function onError(msg, trace) { 2188 page.onError = function onError(msg, trace) {
2184 casper.emit('page.error', msg, trace); 2189 casper.emit('page.error', msg, trace);
2185 }; 2190 };
......
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 });