You should listen to remote.alert event :
casper.on('remote.alert', function(message) {
this.echo('alert message: ' + message);
this.test.assertMatch(message, /Login has failed/);
});
Trying to make it somewhat more synchronous:
function testAlert(message) {
this.test.assertMatch(message, /Login has failed/);
}
casper.then(function() {
this.on('remote.alert', testAlert);
});
casper.waitForSelector('#login', function success() {
this.test.pass('selector was found');
this.click("#login");
}, function fail() {
this.test.fail('selector was found');
});
casper.then(function() {
this.removeListener('remote.alert', testAlert);
});
source
share