Commit 15af4dc9 15af4dc95e124d610208182e859529e87982cb44 by Nicolas Perriault

fixes #125 - support for confirm() and prompt()

1 parent a3ca065c
......@@ -13,6 +13,7 @@ XXXX-XX-XX, v1.0
- fixed [#144](https://github.com/n1k0/casperjs/issues/144) - added a [`safeLogs` option](http://casperjs.org/api.html#casper.options) to blur password values in debug logs. **This option is set to `true` by default.**
- fixed [#157](https://github.com/n1k0/casperjs/issues/157) - added support for PhantomJS 1.6 `WebPage#zoomFactor`
- fixed failed test messages didn't expose the subject correctly
- added support for `prompt()` and `confirm()` (PhantomJS 1.6 only) - closes [#125](https://github.com/n1k0/casperjs/issues/125)
- added [`Casper.userAgent()`](http://casperjs.org/api.html#casper.userAgent) to ease a more dynamic setting of user-agent string
- added [`Tester.assertTitleMatch()`](http://casperjs.org/api.html#tester.assertTitleMatch) method
- added [`utils.getPropertyPath()`](http://casperjs.org/api.html#utils.getPropertyPath)
......
......@@ -1473,6 +1473,9 @@ function createPage(casper) {
casper.options.onAlert.call(casper, casper, message);
}
};
page.onConfirm = function onConfirm(message) {
return casper.filter('page.confirm', message) || true;
};
page.onConsoleMessage = function onConsoleMessage(msg) {
var level = "info", test = /^\[casper:(\w+)\]\s?(.*)/.exec(msg);
if (test && test.length === 3) {
......@@ -1535,6 +1538,9 @@ function createPage(casper) {
casper.emit('load.finished', status);
casper.loadInProgress = false;
};
page.onPrompt = function onPrompt(message, value) {
return casper.filter('page.prompt', message, value);
};
page.onResourceReceived = function onResourceReceived(resource) {
casper.emit('resource.received', resource);
if (utils.isFunction(casper.options.onResourceReceived)) {
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS test confirm</title>
</head>
<body>
<script>
var confirmed = confirm('are you sure?');
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS test prompt</title>
</head>
<body>
<script>
var name = prompt('what is your name?', 'Norris');
</script>
</body>
</html>
var received;
casper.setFilter('page.confirm', function(message) {
received = message;
return true;
});
casper.start('tests/site/confirm.html', function() {
this.test.assert(this.getGlobal('confirmed'), 'confirmation received');
});
casper.run(function() {
this.test.assertEquals(received, 'are you sure?', 'confirmation message is ok');
this.test.done();
});
......@@ -35,4 +35,4 @@ casper.test.assertEquals(casper.foo, 42, "filter() applies the correct context")
delete casper.foo;
casper.test.done();
\ No newline at end of file
casper.test.done();
......
casper.setFilter('page.prompt', function(message, value) {
return 'Chuck ' + value;
});
casper.start('tests/site/prompt.html', function() {
this.test.assertEquals(this.getGlobal('name'), 'Chuck Norris', 'prompted value has been received');
});
casper.run(function() {
this.test.done();
});