Commit c53882b8 c53882b84ecae5bf700d999c02371d70848bd34a by Nicolas Perriault

fixes #317, fixes #313: revert to emulated mouse events

1 parent a36a7fad
...@@ -6,6 +6,12 @@ XXXX-XX-XX, v1.0.0 ...@@ -6,6 +6,12 @@ XXXX-XX-XX, v1.0.0
6 6
7 ### Important Changes & Caveats 7 ### Important Changes & Caveats
8 8
9 #### Reverted to emulated mouse events
10
11 For some (weird) reason, emulated mouse events are actually more accurate than native ones.
12
13 Weird, I said.
14
9 #### Added support for frames 15 #### Added support for frames
10 16
11 Short excerpt of related tests: 17 Short excerpt of related tests:
......
...@@ -1135,18 +1135,22 @@ Casper.prototype.log = function log(message, level, space) { ...@@ -1135,18 +1135,22 @@ Casper.prototype.log = function log(message, level, space) {
1135 Casper.prototype.mouseEvent = function mouseEvent(type, selector) { 1135 Casper.prototype.mouseEvent = function mouseEvent(type, selector) {
1136 "use strict"; 1136 "use strict";
1137 this.checkStarted(); 1137 this.checkStarted();
1138 this.log(f("Mouse event '%s' on selector: %s", type, selector), "debug"); 1138 this.log("Mouse event '" + type + "' on selector: " + selector, "debug");
1139 if (!this.exists(selector)) { 1139 if (!this.exists(selector)) {
1140 throw new CasperError(f("Cannot dispatch '%s' event on nonexistent selector: %s", type, selector)); 1140 throw new CasperError(f("Cannot dispatch %s event on nonexistent selector: %s", type, selector));
1141 } 1141 }
1142 // PhantomJS doesn't provide native events for mouseover & mouseout 1142 if (this.evaluate(function(type, selector) {
1143 if (type === "mouseover" || type === "mouseout") { 1143 return window.__utils__.mouseEvent(type, selector);
1144 return this.evaluate(function(type, selector) { 1144 }, type, selector)) {
1145 return __utils__.mouseEvent(type, selector); 1145 return true;
1146 }, type, selector);
1147 } 1146 }
1148 this.mouse.processEvent(type, selector); 1147 // fallback onto native QtWebKit mouse events
1149 return true; 1148 try {
1149 return this.mouse.processEvent(type, selector);
1150 } catch (e) {
1151 this.log(f("Couldn't emulate '%s' event on %s: %s", type, selector, e), "error");
1152 }
1153 return false;
1150 }; 1154 };
1151 1155
1152 /** 1156 /**
...@@ -1891,6 +1895,9 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on ...@@ -1891,6 +1895,9 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on
1891 Casper.prototype.withFrame = function withFrame(frameName, then) { 1895 Casper.prototype.withFrame = function withFrame(frameName, then) {
1892 "use strict"; 1896 "use strict";
1893 this.then(function _step() { 1897 this.then(function _step() {
1898 if (this.page.childFramesName().indexOf(frameName) === -1) {
1899 throw new CasperError(f('No frame named "%s" was found.', frameName));
1900 }
1894 // make the frame page the currently active one 1901 // make the frame page the currently active one
1895 this.page.switchToChildFrame(frameName); 1902 this.page.switchToChildFrame(frameName);
1896 }); 1903 });
...@@ -1898,7 +1905,7 @@ Casper.prototype.withFrame = function withFrame(frameName, then) { ...@@ -1898,7 +1905,7 @@ Casper.prototype.withFrame = function withFrame(frameName, then) {
1898 this.then(then); 1905 this.then(then);
1899 } catch (e) { 1906 } catch (e) {
1900 // revert to main page on error 1907 // revert to main page on error
1901 this.log("error while processing frame step: " + e, "error"); 1908 this.warn("Error while processing frame step: " + e);
1902 this.page.switchToMainFrame(); 1909 this.page.switchToMainFrame();
1903 throw e; 1910 throw e;
1904 } 1911 }
......
...@@ -4,5 +4,7 @@ ...@@ -4,5 +4,7 @@
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS frame 1</title> 5 <title>CasperJS frame 1</title>
6 </head> 6 </head>
7 <body id="f1">This is frame 1.</body> 7 <body id="f1">
8 <h1>This is frame 1.</h1>
9 </body>
8 </html> 10 </html>
......
...@@ -4,5 +4,8 @@ ...@@ -4,5 +4,8 @@
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS frame 2</title> 5 <title>CasperJS frame 2</title>
6 </head> 6 </head>
7 <body id="f2">This is frame 2.</body> 7 <body id="f2">
8 <h1>This is frame 2.</h1>
9 <p><a href="frame3.html" target="frame2">frame 3</a></p>
10 </body>
8 </html> 11 </html>
......
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS frame 3</title>
6 </head>
7 <body id="f3">
8 <h1>This is frame 3.</h1>
9 <p><a href="frame2.html">frame 2</a></p>
10 </body>
11 </html>
...@@ -28,9 +28,14 @@ casper.withFrame('frame2', function() { ...@@ -28,9 +28,14 @@ casper.withFrame('frame2', function() {
28 this.test.assertEval(function() { 28 this.test.assertEval(function() {
29 return '__utils__' in window && 'getBinary' in __utils__; 29 return '__utils__' in window && 'getBinary' in __utils__;
30 }, '__utils__ object is available in other child frame'); 30 }, '__utils__ object is available in other child frame');
31 this.clickLabel('frame 3');
32 });
33
34 casper.withFrame('frame2', function() {
35 this.test.assertTitle('CasperJS frame 3');
31 }); 36 });
32 37
33 casper.run(function() { 38 casper.run(function() {
34 this.test.assertTitle('CasperJS test frames'); 39 this.test.assertTitle('CasperJS test frames');
35 this.test.done(13); 40 this.test.done(14);
36 }); 41 });
......