Merge pull request #375 from lukeasrodgers/bugfix_getFormValues
Bugfix get form values
Showing
2 changed files
with
28 additions
and
3 deletions
... | @@ -478,7 +478,7 @@ | ... | @@ -478,7 +478,7 @@ |
478 | if (type === 'radio') { | 478 | if (type === 'radio') { |
479 | var value; | 479 | var value; |
480 | [].forEach.call(inputs, function(radio) { | 480 | [].forEach.call(inputs, function(radio) { |
481 | value = radio.checked ? radio.value : undefined; | 481 | value = radio.checked ? radio.value : value; |
482 | }); | 482 | }); |
483 | return value; | 483 | return value; |
484 | } else if (type === 'checkbox') { | 484 | } else if (type === 'checkbox') { |
... | @@ -511,7 +511,7 @@ | ... | @@ -511,7 +511,7 @@ |
511 | var self = this; | 511 | var self = this; |
512 | [].forEach.call(form.elements, function(element) { | 512 | [].forEach.call(form.elements, function(element) { |
513 | var name = element.getAttribute('name'); | 513 | var name = element.getAttribute('name'); |
514 | if (name) { | 514 | if (name && !values[name]) { |
515 | values[name] = self.getFieldValue(name); | 515 | values[name] = self.getFieldValue(name); |
516 | } | 516 | } |
517 | }); | 517 | }); | ... | ... |
... | @@ -92,7 +92,7 @@ casper.test.begin('field array', 1, function(test) { | ... | @@ -92,7 +92,7 @@ casper.test.begin('field array', 1, function(test) { |
92 | }); | 92 | }); |
93 | }); | 93 | }); |
94 | 94 | ||
95 | casper.test.begin('getFormValues() tests', 1, function(test) { | 95 | casper.test.begin('getFormValues() tests', 2, function(test) { |
96 | casper.start('tests/site/form.html', function() { | 96 | casper.start('tests/site/form.html', function() { |
97 | this.fill('form[action="result.html"]', { | 97 | this.fill('form[action="result.html"]', { |
98 | email: 'chuck@norris.com', | 98 | email: 'chuck@norris.com', |
... | @@ -118,6 +118,31 @@ casper.test.begin('getFormValues() tests', 1, function(test) { | ... | @@ -118,6 +118,31 @@ casper.test.begin('getFormValues() tests', 1, function(test) { |
118 | "topic": "bar" | 118 | "topic": "bar" |
119 | }, 'Casper.getFormValues() retrieves filled values'); | 119 | }, 'Casper.getFormValues() retrieves filled values'); |
120 | }); | 120 | }); |
121 | casper.then(function() { | ||
122 | this.fill('form[action="result.html"]', { | ||
123 | email: 'chuck@norris.com', | ||
124 | password: 'chuck', | ||
125 | content: 'Am watching thou', | ||
126 | check: true, | ||
127 | choice: 'yes', | ||
128 | topic: 'bar', | ||
129 | file: phantom.libraryPath + '/README.md', | ||
130 | 'checklist[]': ['1', '3'] | ||
131 | }); | ||
132 | }); | ||
133 | casper.then(function() { | ||
134 | test.assertEquals(this.getFormValues('form'), { | ||
135 | "check": true, | ||
136 | "checklist[]": ["1", "3"], | ||
137 | "choice": "yes", | ||
138 | "content": "Am watching thou", | ||
139 | "email": "chuck@norris.com", | ||
140 | "file": "C:\\fakepath\\README.md", | ||
141 | "password": "chuck", | ||
142 | "submit": "submit", | ||
143 | "topic": "bar" | ||
144 | }, 'Casper.getFormValues() correctly retrieves values from radio inputs regardless of order'); | ||
145 | }); | ||
121 | casper.run(function() { | 146 | casper.run(function() { |
122 | test.done(); | 147 | test.done(); |
123 | }); | 148 | }); | ... | ... |
-
Please register or sign in to post a comment