added Casper.options.onAlert() callback
Showing
3 changed files
with
27 additions
and
0 deletions
... | @@ -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'); | ... | ... |
-
Please register or sign in to post a comment