Commit b025ea98 b025ea98f9cc7231d2f2b2ee1516c77f07fff4e0 by Nicolas Perriault

added Casper.options.onAlert() callback

1 parent 4dd4b736
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
45 faultTolerant: true, 45 faultTolerant: true,
46 logLevel: "error", 46 logLevel: "error",
47 httpStatusHandlers: {}, 47 httpStatusHandlers: {},
48 onAlert: null,
48 onDie: null, 49 onDie: null,
49 onError: null, 50 onError: null,
50 onLoadError: null, 51 onLoadError: null,
...@@ -1661,6 +1662,12 @@ ...@@ -1661,6 +1662,12 @@
1661 } else { 1662 } else {
1662 page = require('webpage').create(); 1663 page = require('webpage').create();
1663 } 1664 }
1665 page.onAlert = function(message) {
1666 casper.log('[alert] ' + message, "info", "remote");
1667 if (isType(casper.options.onAlert, "function")) {
1668 casper.options.onAlert.call(casper, casper, message);
1669 }
1670 };
1664 page.onConsoleMessage = function(msg) { 1671 page.onConsoleMessage = function(msg) {
1665 var level = "info", test = /^\[casper:(\w+)\]\s?(.*)/.exec(msg); 1672 var level = "info", test = /^\[casper:(\w+)\]\s?(.*)/.exec(msg);
1666 if (test && test.length === 3) { 1673 if (test && test.length === 3) {
......
...@@ -259,6 +259,16 @@ casper ...@@ -259,6 +259,16 @@ casper
259 }) 259 })
260 ; 260 ;
261 261
262 // Casper.options.onAlert()
263 casper.then(function(self) {
264 self.options.onAlert = function(self, message) {
265 self.test.assertEquals(message, 'plop', 'Casper.options.onAlert() can intercept an alert message');
266 };
267 });
268 casper.thenOpen('tests/site/alert.html').click('button', function(self) {
269 self.options.onAlert = null;
270 });
271
262 // run suite 272 // run suite
263 casper.run(function(self) { 273 casper.run(function(self) {
264 casper.test.comment('history'); 274 casper.test.comment('history');
......
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS test alert</title>
6 </head>
7 <body>
8 <script>alert('plop')</script>
9 </body>
10 </html>