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 ...@@ -13,6 +13,7 @@ XXXX-XX-XX, v1.0
13 - 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.** 13 - 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.**
14 - fixed [#157](https://github.com/n1k0/casperjs/issues/157) - added support for PhantomJS 1.6 `WebPage#zoomFactor` 14 - fixed [#157](https://github.com/n1k0/casperjs/issues/157) - added support for PhantomJS 1.6 `WebPage#zoomFactor`
15 - fixed failed test messages didn't expose the subject correctly 15 - fixed failed test messages didn't expose the subject correctly
16 - added support for `prompt()` and `confirm()` (PhantomJS 1.6 only) - closes [#125](https://github.com/n1k0/casperjs/issues/125)
16 - added [`Casper.userAgent()`](http://casperjs.org/api.html#casper.userAgent) to ease a more dynamic setting of user-agent string 17 - added [`Casper.userAgent()`](http://casperjs.org/api.html#casper.userAgent) to ease a more dynamic setting of user-agent string
17 - added [`Tester.assertTitleMatch()`](http://casperjs.org/api.html#tester.assertTitleMatch) method 18 - added [`Tester.assertTitleMatch()`](http://casperjs.org/api.html#tester.assertTitleMatch) method
18 - added [`utils.getPropertyPath()`](http://casperjs.org/api.html#utils.getPropertyPath) 19 - added [`utils.getPropertyPath()`](http://casperjs.org/api.html#utils.getPropertyPath)
......
...@@ -1473,6 +1473,9 @@ function createPage(casper) { ...@@ -1473,6 +1473,9 @@ function createPage(casper) {
1473 casper.options.onAlert.call(casper, casper, message); 1473 casper.options.onAlert.call(casper, casper, message);
1474 } 1474 }
1475 }; 1475 };
1476 page.onConfirm = function onConfirm(message) {
1477 return casper.filter('page.confirm', message) || true;
1478 };
1476 page.onConsoleMessage = function onConsoleMessage(msg) { 1479 page.onConsoleMessage = function onConsoleMessage(msg) {
1477 var level = "info", test = /^\[casper:(\w+)\]\s?(.*)/.exec(msg); 1480 var level = "info", test = /^\[casper:(\w+)\]\s?(.*)/.exec(msg);
1478 if (test && test.length === 3) { 1481 if (test && test.length === 3) {
...@@ -1535,6 +1538,9 @@ function createPage(casper) { ...@@ -1535,6 +1538,9 @@ function createPage(casper) {
1535 casper.emit('load.finished', status); 1538 casper.emit('load.finished', status);
1536 casper.loadInProgress = false; 1539 casper.loadInProgress = false;
1537 }; 1540 };
1541 page.onPrompt = function onPrompt(message, value) {
1542 return casper.filter('page.prompt', message, value);
1543 };
1538 page.onResourceReceived = function onResourceReceived(resource) { 1544 page.onResourceReceived = function onResourceReceived(resource) {
1539 casper.emit('resource.received', resource); 1545 casper.emit('resource.received', resource);
1540 if (utils.isFunction(casper.options.onResourceReceived)) { 1546 if (utils.isFunction(casper.options.onResourceReceived)) {
......
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS test confirm</title>
6 </head>
7 <body>
8 <script>
9 var confirmed = confirm('are you sure?');
10 </script>
11 </body>
12 </html>
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS test prompt</title>
6 </head>
7 <body>
8 <script>
9 var name = prompt('what is your name?', 'Norris');
10 </script>
11 </body>
12 </html>
1 var received;
2
3 casper.setFilter('page.confirm', function(message) {
4 received = message;
5 return true;
6 });
7
8 casper.start('tests/site/confirm.html', function() {
9 this.test.assert(this.getGlobal('confirmed'), 'confirmation received');
10 });
11
12 casper.run(function() {
13 this.test.assertEquals(received, 'are you sure?', 'confirmation message is ok');
14 this.test.done();
15 });
...@@ -35,4 +35,4 @@ casper.test.assertEquals(casper.foo, 42, "filter() applies the correct context") ...@@ -35,4 +35,4 @@ casper.test.assertEquals(casper.foo, 42, "filter() applies the correct context")
35 35
36 delete casper.foo; 36 delete casper.foo;
37 37
38 casper.test.done();
...\ No newline at end of file ...\ No newline at end of file
38 casper.test.done();
......
1 casper.setFilter('page.prompt', function(message, value) {
2 return 'Chuck ' + value;
3 });
4
5 casper.start('tests/site/prompt.html', function() {
6 this.test.assertEquals(this.getGlobal('name'), 'Chuck Norris', 'prompted value has been received');
7 });
8
9 casper.run(function() {
10 this.test.done();
11 });