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
### Important Changes & Caveats
#### Reverted to emulated mouse events
For some (weird) reason, emulated mouse events are actually more accurate than native ones.
Weird, I said.
#### Added support for frames
Short excerpt of related tests:
......
......@@ -1135,18 +1135,22 @@ Casper.prototype.log = function log(message, level, space) {
Casper.prototype.mouseEvent = function mouseEvent(type, selector) {
"use strict";
this.checkStarted();
this.log(f("Mouse event '%s' on selector: %s", type, selector), "debug");
this.log("Mouse event '" + type + "' on selector: " + selector, "debug");
if (!this.exists(selector)) {
throw new CasperError(f("Cannot dispatch '%s' event on nonexistent selector: %s", type, selector));
throw new CasperError(f("Cannot dispatch %s event on nonexistent selector: %s", type, selector));
}
// PhantomJS doesn't provide native events for mouseover & mouseout
if (type === "mouseover" || type === "mouseout") {
return this.evaluate(function(type, selector) {
return __utils__.mouseEvent(type, selector);
}, type, selector);
if (this.evaluate(function(type, selector) {
return window.__utils__.mouseEvent(type, selector);
}, type, selector)) {
return true;
}
this.mouse.processEvent(type, selector);
return true;
// fallback onto native QtWebKit mouse events
try {
return this.mouse.processEvent(type, selector);
} catch (e) {
this.log(f("Couldn't emulate '%s' event on %s: %s", type, selector, e), "error");
}
return false;
};
/**
......@@ -1891,6 +1895,9 @@ Casper.prototype.waitWhileVisible = function waitWhileVisible(selector, then, on
Casper.prototype.withFrame = function withFrame(frameName, then) {
"use strict";
this.then(function _step() {
if (this.page.childFramesName().indexOf(frameName) === -1) {
throw new CasperError(f('No frame named "%s" was found.', frameName));
}
// make the frame page the currently active one
this.page.switchToChildFrame(frameName);
});
......@@ -1898,7 +1905,7 @@ Casper.prototype.withFrame = function withFrame(frameName, then) {
this.then(then);
} catch (e) {
// revert to main page on error
this.log("error while processing frame step: " + e, "error");
this.warn("Error while processing frame step: " + e);
this.page.switchToMainFrame();
throw e;
}
......
......@@ -4,5 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS frame 1</title>
</head>
<body id="f1">This is frame 1.</body>
<body id="f1">
<h1>This is frame 1.</h1>
</body>
</html>
......
......@@ -4,5 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS frame 2</title>
</head>
<body id="f2">This is frame 2.</body>
<body id="f2">
<h1>This is frame 2.</h1>
<p><a href="frame3.html" target="frame2">frame 3</a></p>
</body>
</html>
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS frame 3</title>
</head>
<body id="f3">
<h1>This is frame 3.</h1>
<p><a href="frame2.html">frame 2</a></p>
</body>
</html>
......@@ -28,9 +28,14 @@ casper.withFrame('frame2', function() {
this.test.assertEval(function() {
return '__utils__' in window && 'getBinary' in __utils__;
}, '__utils__ object is available in other child frame');
this.clickLabel('frame 3');
});
casper.withFrame('frame2', function() {
this.test.assertTitle('CasperJS frame 3');
});
casper.run(function() {
this.test.assertTitle('CasperJS test frames');
this.test.done(13);
this.test.done(14);
});
......