Commit 2b185aac 2b185aac21600506388ba3b119cd8d1e49a7b69b by Nicolas Perriault

fixes #544 - treat any input tag type as valid when filling forms

1 parent 130e23f7
...@@ -766,24 +766,6 @@ ...@@ -766,24 +766,6 @@
766 case "input": 766 case "input":
767 var type = field.getAttribute('type') || "text"; 767 var type = field.getAttribute('type') || "text";
768 switch (type.toLowerCase()) { 768 switch (type.toLowerCase()) {
769 case "color":
770 case "date":
771 case "datetime":
772 case "datetime-local":
773 case "email":
774 case "hidden":
775 case "month":
776 case "number":
777 case "password":
778 case "range":
779 case "search":
780 case "tel":
781 case "text":
782 case "time":
783 case "url":
784 case "week":
785 field.value = value;
786 break;
787 case "checkbox": 769 case "checkbox":
788 if (fields.length > 1) { 770 if (fields.length > 1) {
789 var values = value; 771 var values = value;
...@@ -813,7 +795,7 @@ ...@@ -813,7 +795,7 @@
813 } 795 }
814 break; 796 break;
815 default: 797 default:
816 out = "Unsupported input field type: " + type; 798 field.value = value;
817 break; 799 break;
818 } 800 }
819 break; 801 break;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
9 <input type="text" name="email" placeholder="email"> 9 <input type="text" name="email" placeholder="email">
10 <input type="password" name="password" placeholder="password"> 10 <input type="password" name="password" placeholder="password">
11 <input type="text" name="language" placeholder="language"> 11 <input type="text" name="language" placeholder="language">
12 <input type="whatever" name="strange">
12 <textarea name="content"></textarea> 13 <textarea name="content"></textarea>
13 <select name="topic"> 14 <select name="topic">
14 <option>foo</option> 15 <option>foo</option>
......
...@@ -33,9 +33,10 @@ function testUrl(test) { ...@@ -33,9 +33,10 @@ function testUrl(test) {
33 test.assertUrlMatch(/check=on/, 'input[type=checkbox] field was submitted'); 33 test.assertUrlMatch(/check=on/, 'input[type=checkbox] field was submitted');
34 test.assertUrlMatch(/choice=no/, 'input[type=radio] field was submitted'); 34 test.assertUrlMatch(/choice=no/, 'input[type=radio] field was submitted');
35 test.assertUrlMatch(/topic=bar/, 'select field was submitted'); 35 test.assertUrlMatch(/topic=bar/, 'select field was submitted');
36 test.assertUrlMatch(/strange=very/, 'strangely typed input field was submitted');
36 } 37 }
37 38
38 casper.test.begin('fill() & fillNames() tests', 15, function(test) { 39 casper.test.begin('fill() & fillNames() tests', 16, function(test) {
39 var fpath = fs.pathJoin(phantom.casperPath, 'README.md'); 40 var fpath = fs.pathJoin(phantom.casperPath, 'README.md');
40 41
41 casper.start('tests/site/form.html', function() { 42 casper.start('tests/site/form.html', function() {
...@@ -47,7 +48,8 @@ casper.test.begin('fill() & fillNames() tests', 15, function(test) { ...@@ -47,7 +48,8 @@ casper.test.begin('fill() & fillNames() tests', 15, function(test) {
47 choice: 'no', 48 choice: 'no',
48 topic: 'bar', 49 topic: 'bar',
49 file: fpath, 50 file: fpath,
50 'checklist[]': ['1', '3'] 51 'checklist[]': ['1', '3'],
52 strange: "very"
51 }); 53 });
52 testFormValues(test); 54 testFormValues(test);
53 test.assertEvalEquals(function() { 55 test.assertEvalEquals(function() {
...@@ -62,7 +64,7 @@ casper.test.begin('fill() & fillNames() tests', 15, function(test) { ...@@ -62,7 +64,7 @@ casper.test.begin('fill() & fillNames() tests', 15, function(test) {
62 }); 64 });
63 }); 65 });
64 66
65 casper.test.begin('fillSelectors() tests', 15, function(test) { 67 casper.test.begin('fillSelectors() tests', 16, function(test) {
66 var fpath = fs.pathJoin(phantom.casperPath, 'README.md'); 68 var fpath = fs.pathJoin(phantom.casperPath, 'README.md');
67 69
68 casper.start('tests/site/form.html', function() { 70 casper.start('tests/site/form.html', function() {
...@@ -74,7 +76,8 @@ casper.test.begin('fillSelectors() tests', 15, function(test) { ...@@ -74,7 +76,8 @@ casper.test.begin('fillSelectors() tests', 15, function(test) {
74 "input[name='choice']": 'no', 76 "input[name='choice']": 'no',
75 "select[name='topic']": 'bar', 77 "select[name='topic']": 'bar',
76 "input[name='file']": fpath, 78 "input[name='file']": fpath,
77 "input[name='checklist[]']": ['1', '3'] 79 "input[name='checklist[]']": ['1', '3'],
80 "input[name='strange']": "very"
78 }); 81 });
79 testFormValues(test); 82 testFormValues(test);
80 test.assertEvalEquals(function() { 83 test.assertEvalEquals(function() {
...@@ -89,7 +92,7 @@ casper.test.begin('fillSelectors() tests', 15, function(test) { ...@@ -89,7 +92,7 @@ casper.test.begin('fillSelectors() tests', 15, function(test) {
89 }); 92 });
90 }); 93 });
91 94
92 casper.test.begin('fillXPath() tests', 14, function(test) { 95 casper.test.begin('fillXPath() tests', 15, function(test) {
93 casper.start('tests/site/form.html', function() { 96 casper.start('tests/site/form.html', function() {
94 this.fillXPath('form[action="result.html"]', { 97 this.fillXPath('form[action="result.html"]', {
95 '//input[@name="email"]': 'chuck@norris.com', 98 '//input[@name="email"]': 'chuck@norris.com',
...@@ -98,7 +101,8 @@ casper.test.begin('fillXPath() tests', 14, function(test) { ...@@ -98,7 +101,8 @@ casper.test.begin('fillXPath() tests', 14, function(test) {
98 '//input[@name="check"]': true, 101 '//input[@name="check"]': true,
99 '//input[@name="choice"]': 'no', 102 '//input[@name="choice"]': 'no',
100 '//select[@name="topic"]': 'bar', 103 '//select[@name="topic"]': 'bar',
101 '//input[@name="checklist[]"]': ['1', '3'] 104 '//input[@name="checklist[]"]': ['1', '3'],
105 '//input[@name="strange"]': "very"
102 }); 106 });
103 testFormValues(test); 107 testFormValues(test);
104 // note: file inputs cannot be filled using XPath 108 // note: file inputs cannot be filled using XPath
...@@ -173,7 +177,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) { ...@@ -173,7 +177,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
173 choice: 'no', 177 choice: 'no',
174 topic: 'bar', 178 topic: 'bar',
175 file: fpath, 179 file: fpath,
176 'checklist[]': ['1', '3'] 180 'checklist[]': ['1', '3'],
181 strange: "very"
177 }); 182 });
178 }); 183 });
179 casper.then(function() { 184 casper.then(function() {
...@@ -187,7 +192,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) { ...@@ -187,7 +192,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
187 "password": "chuck", 192 "password": "chuck",
188 "submit": "submit", 193 "submit": "submit",
189 "language": "english", 194 "language": "english",
190 "topic": "bar" 195 "topic": "bar",
196 "strange": "very"
191 }, 'Casper.getFormValues() retrieves filled values'); 197 }, 'Casper.getFormValues() retrieves filled values');
192 }); 198 });
193 casper.then(function() { 199 casper.then(function() {
...@@ -200,7 +206,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) { ...@@ -200,7 +206,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
200 choice: 'yes', 206 choice: 'yes',
201 topic: 'bar', 207 topic: 'bar',
202 file: fpath, 208 file: fpath,
203 'checklist[]': ['1', '3'] 209 'checklist[]': ['1', '3'],
210 strange: "very"
204 }); 211 });
205 }); 212 });
206 casper.then(function() { 213 casper.then(function() {
...@@ -214,7 +221,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) { ...@@ -214,7 +221,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
214 "password": "chuck", 221 "password": "chuck",
215 "language": "english", 222 "language": "english",
216 "submit": "submit", 223 "submit": "submit",
217 "topic": "bar" 224 "topic": "bar",
225 "strange": "very"
218 }, 'Casper.getFormValues() correctly retrieves values from radio inputs regardless of order'); 226 }, 'Casper.getFormValues() correctly retrieves values from radio inputs regardless of order');
219 }); 227 });
220 casper.run(function() { 228 casper.run(function() {
......