Commit a2ab8b42 a2ab8b42f639913530936c2346f61b88101c389d by Nicolas Perriault

updated `Casper.evaluate()` to use phantomjs >= 1.6 native one.

As a consequence, the `injector` module is now deprecated.
1 parent fe0859af
......@@ -8,6 +8,7 @@ This version is yet to be released.
### Important Changes & Caveats
- the `injector` module is now deprecated, but kept for backward compatibility purpose.
- **BC BREAK**: fixes [#220](https://github.com/n1k0/casperjs/issues/220), [#237](https://github.com/n1k0/casperjs/issues/237) - added a `waitTimeout` options, removed `defaultWaitTimeout` option.
- **BC BREAK** (for the better): fixes [#249](https://github.com/n1k0/casperjs/issues/249) - default timeout functions don't `die()` anymore in tests
- **BC BREAK** (for the better): merged [#188](https://github.com/n1k0/casperjs/issues/188) - Easy access to current response object;
......@@ -69,8 +70,9 @@ The documentation has been [updated accordingly](http://casperjs.org/api.html#ca
- [Casper.resourceExists()](http://casperjs.org/api.html#casper.resourceExists) and related functions now checks for non HTTP-404 received responses.
- closes [#205](https://github.com/n1k0/casperjs/issues/205) - [`debugHTML()`](http://casperjs.org/api.html#casper.debugHTML) can have a selector passed; added [`getHTML()`](http://casperjs.org/api.html#casper.getHTML)
- closes [#230](https://github.com/n1k0/casperjs/issues/230) - added [`ClientUtils.getElementsBound()`](http://casperjs.org/api.html#clientutils.getElementsBounds) and [`Casper.getElementsBound()`](http://casperjs.org/api.html#casper.getElementsBounds)
- fixed [#235](https://github.com/n1k0/casperjs/issues/235) - updated `Casper.evaluate()` to use phantomjs >= 1.6 native one. As a consequence, **the `injector` module is marked as deprecated**.
- fixed [#250](https://github.com/n1k0/casperjs/issues/250) - prevent self tests to be run using the standard `casper test` command
- fixes [#254](https://github.com/n1k0/casperjs/issues/254) - fix up one use of qsa, hit when filling forms with missing elements
- fixed [#254](https://github.com/n1k0/casperjs/issues/254) - fix up one use of qsa, hit when filling forms with missing elements
2012-10-01, v1.0.0-RC2
----------------------
......
......@@ -540,7 +540,6 @@ Casper.prototype.echo = function echo(text, style, pad) {
*
* FIXME: waiting for a patch of PhantomJS to allow direct passing of
* arguments to the function.
* TODO: don't forget to keep this backward compatible.
*
* @param Function fn The function to be evaluated within current page DOM
* @param Object context Object containing the parameters to inject into the function
......@@ -551,10 +550,13 @@ Casper.prototype.evaluate = function evaluate(fn, context) {
"use strict";
// ensure client utils are always injected
this.injectClientUtils();
// function processing
// function context
context = utils.isObject(context) ? context : {};
var newFn = require('injector').create(fn).process(context);
return this.page.evaluate(newFn);
// the way this works is kept for BC with older casperjs versions
var args = Object.keys(context).map(function(arg) {
return context[arg];
});
return this.page.evaluate.apply(this.page, [fn].concat(args));
};
/**
......
......@@ -30,6 +30,8 @@
/*global CasperError console encodeURIComponent escape exports require*/
// WARNING: this module is deprecated since CasperJS 1.0.0-RC3
var utils = require('utils');
exports.create = function create(fn) {
......@@ -44,6 +46,8 @@ exports.create = function create(fn) {
*/
var FunctionArgsInjector = function FunctionArgsInjector(fn) {
"use strict";
console.error('Warning: the injector module has been deprecated.');
if (!utils.isFunction(fn)) {
throw new CasperError("FunctionArgsInjector() can only process functions");
}
......
......@@ -2,26 +2,32 @@ casper.test.comment('Casper.evaluate()');
casper.start();
var params = {
"boolean true": true,
"boolean false": false,
"int number": 42,
"float number": 1337.42,
"string": "plop! \"Ÿ£$\" 'no'",
"array": [1, 2, 3],
"object": {a: 1, b: 2}
var context = {
"_boolean_true": true,
"_boolean_false": false,
"_int_number": 42,
"_float_number": 1337.42,
"_string": "plop! \"Ÿ£$\" 'no'",
"_array": [1, 2, 3],
"_object": {a: 1, b: 2},
"_function": function(){console.log('ok');}
};
var casperParams = casper.evaluate(function() {
return __casper_params__;
}, params);
var result = casper.evaluate(function(_boolean_true,
_boolean_false,
_int_number,
_float_number,
_string,
_array,
_object,
_function) {
return [].map.call(arguments, function(arg) {
return typeof(arg);
});
}, context);
casper.test.assertType(casperParams, "object", 'Casper.evaluate() exposes parameters in a dedicated object');
casper.test.assertEquals(Object.keys(casperParams).length, 7, 'Casper.evaluate() object containing parameters has the correct length');
for (var param in casperParams) {
casper.test.assertEquals(JSON.stringify(casperParams[param]), JSON.stringify(params[param]), 'Casper.evaluate() can pass a ' + param);
casper.test.assertEquals(typeof casperParams[param], typeof params[param], 'Casper.evaluate() preserves the ' + param + ' type');
}
casper.test.assertEquals(result.toString(),
['boolean', 'boolean', 'number', 'number', 'string', 'object', 'object', 'function'].toString(),
'Casper.evaluate() handles passed argument context correcly');
casper.test.done();
......