AC: Add assertField to tester module.
Showing
3 changed files
with
28 additions
and
0 deletions
... | @@ -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 | * | ... | ... |
... | @@ -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 | }); | ... | ... |
-
Please register or sign in to post a comment