Commit 0a603803 0a603803cd44f7f88d793b4eed3e10c8ffeb8780 by Nicolas Perriault

Casper.mouseEvent() now uses native events for most operations

Native mouse events from PhantomJS bring a far more accurate behavior.
1 parent 40efda01
......@@ -24,7 +24,7 @@ casper.evaluate(function(a, b) {
}, {a: "foo", b: "bar"}); // true
```
#### Specification of planned tests ####
#### Specification of planned tests
In order to check that every planned test has actuall been executed, a new optional `planned` parameter has been added to `Tester.done()`:
......@@ -45,6 +45,10 @@ That's especially useful in case a given test script is abruptly interrupted lea
The whole [CapserJS test suite](https://github.com/n1k0/casperjs/tree/master/tests/) has been migrated to use this new feature.
#### `Casper.mouseEvent()` now uses native events for most operations
Native mouse events from PhantomJS bring a far more accurate behavior.
### Bugfixes & enhancements
- 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
......
......@@ -1117,17 +1117,17 @@ Casper.prototype.mouseEvent = function mouseEvent(type, selector) {
if (!this.exists(selector)) {
throw new CasperError(f("Cannot dispatch %s event on nonexistent selector: %s", type, selector));
}
var eventSuccess = this.evaluate(function(type, selector) {
return window.__utils__.mouseEvent(type, selector);
}, type, selector);
if (!eventSuccess) {
// fallback onto native QtWebKit mouse events
try {
this.mouse.processEvent(type, selector);
} catch (e) {
this.log(f("Couldn't emulate '%s' event on %s: %s", type, selector, e), "error");
return false;
}
// PhantomJS doesn't provide native events for mouseover & mouseout
if (type === "mouseover" || type === "mouseout") {
return this.evaluate(function(type, selector) {
return window.__utils__.mouseEvent(type, selector);
}, type, selector);
}
try {
this.mouse.processEvent(type, selector);
} catch (e) {
this.log(f("Couldn't emulate '%s' event on %s: %s", type, selector, e), "error");
return false;
}
return true;
};
......
......@@ -58,6 +58,14 @@ casper.then(function() {
this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position');
});
// element focus on click
casper.then(function() {
this.page.content = '<form><input type="text" name="foo"></form>'
this.click('form input[name=foo]')
this.page.sendEvent('keypress', 'bar');
this.test.assertEquals(this.getFormValues('form')['foo'], 'bar', 'Casper.click() sets the focus on clicked element');
});
casper.run(function() {
this.test.done(21);
this.test.done(22);
});
......