Commit db638037 db638037de2ad908a07033fe41e46db1af153eeb by Nicolas Perriault

added Casper.getFormValues()

1 parent 8ec3e4e2
......@@ -33,6 +33,7 @@ casper.evaluate(function(a, b) {
- fixed [#282](https://github.com/n1k0/casperjs/issues/282) - added support for remote client scripts loading with a new `remoteScripts` casper option
- merged [#290](https://github.com/n1k0/casperjs/issues/#290) - add a simplistic RPM spec file to make it easier to (un)install casperjs
- fixed `Casper.die()` and `Casper.evaluateOrDie()` were not printing the error onto the console
- added [`Casper.getFormValues()`](http://casperjs.org/api.html#casper.getFormValues) to check for the field values of a given form
- added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist)
- added `Tester.assertFalse()` as an alias of `Tester.assertNot()`
- added `page.resource.requested` and `page.resource.received` events
......
Subproject commit cd0d5fc3efd4279e0ac4062d012cb16d77cbc708
Subproject commit 3b2e87424f41b90efe734e3b64fdf1517f2fb39c
......
......@@ -852,6 +852,23 @@ Casper.prototype.getElementsBounds = function getElementBounds(selector) {
};
/**
* Retrieves a given form all of its field values.
*
* @param String selector A DOM CSS3/XPath selector
* @return Object
*/
Casper.prototype.getFormValues = function(selector) {
"use strict";
this.checkStarted();
if (!this.exists(selector)) {
throw new CasperError(f('Form matching selector "%s" not found', selector));
}
return this.evaluate(function(selector) {
return __utils__.getFormValues(selector);
}, selector);
};
/**
* Retrieves global variable.
*
* @param String name The name of the global variable to retrieve
......
......@@ -469,6 +469,25 @@
};
/**
* Retrieves a given form all of its field values.
*
* @param String selector A DOM CSS3/XPath selector
* @return Object
*/
this.getFormValues = function getFormValues(selector) {
var form = __utils__.findOne(selector);
var values = {};
var self = this;
[].forEach.call(form.elements, function(element) {
var name = element.getAttribute('name');
if (name) {
values[name] = self.getFieldValue(name);
}
});
return values;
};
/**
* Logs a message. Will format the message a way CasperJS will be able
* to log phantomjs side.
*
......
......@@ -41,6 +41,23 @@ casper.start('tests/site/form.html', function() {
!document.querySelector('input[name="checklist[]"][value="2"]').checked &&
document.querySelector('input[name="checklist[]"][value="3"]').checked);
}, true, 'Casper.fill() can fill a list of checkboxes');
});
casper.then(function() {
this.test.comment('Casper.getFormValues()');
this.test.assertEquals(this.getFormValues('form'), {
"check": true,
"checklist[]": ["1", "3"],
"choice": "no",
"content": "Am watching thou",
"email": "chuck@norris.com",
"file": "C:\\fakepath\\README.md",
"password": "chuck",
"submit": "submit",
"topic": "bar"
}, 'Casper.getFormValues() retrieves filled values');
this.test.comment('submitting form');
this.click('input[type="submit"]');
});
......