Commit 626c0455 626c0455daf6a808bab5cf01d5eccd6a1b6ea9f1 by Andrew Childs

AC: Add assertField to tester module.

1 parent b766e4de
...@@ -220,6 +220,30 @@ var Tester = function Tester(casper, options) { ...@@ -220,6 +220,30 @@ var Tester = function Tester(casper, options) {
220 }; 220 };
221 221
222 /** 222 /**
223 * Asserts that a given input field has the provided value.
224 *
225 * @param String input_name The name attribute of the input element
226 * @param String expected_value The expected value of the input element
227 * @param String message Test description
228 * @return Object An assertion result object
229 */
230 this.assertField = function assertField(input_name, expected_value, message) {
231 var actual_value = casper.evaluate(function(input_name) {
232 var input = document.querySelector('input[name="' + input_name + '"]');
233 return input ? input.value : null;
234 }, { input_name: input_name });
235 return this.assert(this.testEquals(actual_value, expected_value), message, {
236 type: 'assertField',
237 standard: f('%s input field has the value %s', this.colorize(input_name, 'COMMENT'), this.colorize(expected_value, 'COMMENT')),
238 values: {
239 input_name: input_name,
240 actual_value: actual_value,
241 expected_value: expected_value
242 }
243 });
244 };
245
246 /**
223 * Asserts that an element matching the provided selector expression exists in 247 * Asserts that an element matching the provided selector expression exists in
224 * remote DOM. 248 * remote DOM.
225 * 249 *
......
...@@ -13,5 +13,6 @@ ...@@ -13,5 +13,6 @@
13 <li>two</li> 13 <li>two</li>
14 <li>three</li> 14 <li>three</li>
15 </ul> 15 </ul>
16 <input type="text" name="dummy_name" value="dummy_value" />
16 </body> 17 </body>
17 </html> 18 </html>
......
...@@ -45,6 +45,9 @@ var expected = [ ...@@ -45,6 +45,9 @@ var expected = [
45 t.assertEquals(files, expected, 'findTestFiles() find test files and sort them'); 45 t.assertEquals(files, expected, 'findTestFiles() find test files and sort them');
46 46
47 casper.thenOpen('tests/site/index.html', function() { 47 casper.thenOpen('tests/site/index.html', function() {
48 t.comment('Tester.assertField()');
49 t.assertField('dummy_name', 'dummy_value', 'Tester.assertField() works as expected');
50
48 t.comment('Tester.assertTextExists()'); 51 t.comment('Tester.assertTextExists()');
49 t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text'); 52 t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text');
50 }); 53 });
......