Commit de27282e de27282e156c56d06cb369ddb22865c41257236e by Nicolas Perriault

Casper.mouseEvent() now triggers an error on failure

1 parent 0a603803
...@@ -49,6 +49,8 @@ The whole [CapserJS test suite](https://github.com/n1k0/casperjs/tree/master/tes ...@@ -49,6 +49,8 @@ The whole [CapserJS test suite](https://github.com/n1k0/casperjs/tree/master/tes
49 49
50 Native mouse events from PhantomJS bring a far more accurate behavior. 50 Native mouse events from PhantomJS bring a far more accurate behavior.
51 51
52 Also, `Casper.mouseEvent()` will now directly trigger an error on failure instead of just logging an `error` event.
53
52 ### Bugfixes & enhancements 54 ### Bugfixes & enhancements
53 55
54 - fixed [#300](https://github.com/n1k0/casperjs/issues/300) - Ensure that `findOne()` and `findAll()` observe the scope for XPath expressions, not just when passed CSS selectors 56 - fixed [#300](https://github.com/n1k0/casperjs/issues/300) - Ensure that `findOne()` and `findAll()` observe the scope for XPath expressions, not just when passed CSS selectors
......
...@@ -1113,9 +1113,9 @@ Casper.prototype.log = function log(message, level, space) { ...@@ -1113,9 +1113,9 @@ Casper.prototype.log = function log(message, level, space) {
1113 Casper.prototype.mouseEvent = function mouseEvent(type, selector) { 1113 Casper.prototype.mouseEvent = function mouseEvent(type, selector) {
1114 "use strict"; 1114 "use strict";
1115 this.checkStarted(); 1115 this.checkStarted();
1116 this.log("Mouse event '" + type + "' on selector: " + selector, "debug"); 1116 this.log(f("Mouse event '%s' on selector: %s", type, selector), "debug");
1117 if (!this.exists(selector)) { 1117 if (!this.exists(selector)) {
1118 throw new CasperError(f("Cannot dispatch %s event on nonexistent selector: %s", type, selector)); 1118 throw new CasperError(f("Cannot dispatch '%s' event on nonexistent selector: %s", type, selector));
1119 } 1119 }
1120 // PhantomJS doesn't provide native events for mouseover & mouseout 1120 // PhantomJS doesn't provide native events for mouseover & mouseout
1121 if (type === "mouseover" || type === "mouseout") { 1121 if (type === "mouseover" || type === "mouseout") {
...@@ -1123,12 +1123,7 @@ Casper.prototype.mouseEvent = function mouseEvent(type, selector) { ...@@ -1123,12 +1123,7 @@ Casper.prototype.mouseEvent = function mouseEvent(type, selector) {
1123 return window.__utils__.mouseEvent(type, selector); 1123 return window.__utils__.mouseEvent(type, selector);
1124 }, type, selector); 1124 }, type, selector);
1125 } 1125 }
1126 try { 1126 this.mouse.processEvent(type, selector);
1127 this.mouse.processEvent(type, selector);
1128 } catch (e) {
1129 this.log(f("Couldn't emulate '%s' event on %s: %s", type, selector, e), "error");
1130 return false;
1131 }
1132 return true; 1127 return true;
1133 }; 1128 };
1134 1129
......
...@@ -72,8 +72,7 @@ var Mouse = function Mouse(casper) { ...@@ -72,8 +72,7 @@ var Mouse = function Mouse(casper) {
72 throw new CasperError('Mouse.processEvent(): Too few arguments'); 72 throw new CasperError('Mouse.processEvent(): Too few arguments');
73 case 1: 73 case 1:
74 // selector 74 // selector
75 var selector = args[0]; 75 casper.page.sendEvent.apply(casper.page, [type].concat(computeCenter(args[0])));
76 casper.page.sendEvent.apply(casper.page, [type].concat(computeCenter(selector)));
77 break; 76 break;
78 case 2: 77 case 2:
79 // coordinates 78 // coordinates
......