Commit b025ea98 b025ea98f9cc7231d2f2b2ee1516c77f07fff4e0 by Nicolas Perriault

added Casper.options.onAlert() callback

1 parent 4dd4b736
......@@ -45,6 +45,7 @@
faultTolerant: true,
logLevel: "error",
httpStatusHandlers: {},
onAlert: null,
onDie: null,
onError: null,
onLoadError: null,
......@@ -1661,6 +1662,12 @@
} else {
page = require('webpage').create();
}
page.onAlert = function(message) {
casper.log('[alert] ' + message, "info", "remote");
if (isType(casper.options.onAlert, "function")) {
casper.options.onAlert.call(casper, casper, message);
}
};
page.onConsoleMessage = function(msg) {
var level = "info", test = /^\[casper:(\w+)\]\s?(.*)/.exec(msg);
if (test && test.length === 3) {
......
......@@ -259,6 +259,16 @@ casper
})
;
// Casper.options.onAlert()
casper.then(function(self) {
self.options.onAlert = function(self, message) {
self.test.assertEquals(message, 'plop', 'Casper.options.onAlert() can intercept an alert message');
};
});
casper.thenOpen('tests/site/alert.html').click('button', function(self) {
self.options.onAlert = null;
});
// run suite
casper.run(function(self) {
casper.test.comment('history');
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS test alert</title>
</head>
<body>
<script>alert('plop')</script>
</body>
</html>