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 @@
case "input":
var type = field.getAttribute('type') || "text";
switch (type.toLowerCase()) {
case "color":
case "date":
case "datetime":
case "datetime-local":
case "email":
case "hidden":
case "month":
case "number":
case "password":
case "range":
case "search":
case "tel":
case "text":
case "time":
case "url":
case "week":
field.value = value;
break;
case "checkbox":
if (fields.length > 1) {
var values = value;
......@@ -813,7 +795,7 @@
}
break;
default:
out = "Unsupported input field type: " + type;
field.value = value;
break;
}
break;
......
......@@ -9,6 +9,7 @@
<input type="text" name="email" placeholder="email">
<input type="password" name="password" placeholder="password">
<input type="text" name="language" placeholder="language">
<input type="whatever" name="strange">
<textarea name="content"></textarea>
<select name="topic">
<option>foo</option>
......
......@@ -33,9 +33,10 @@ function testUrl(test) {
test.assertUrlMatch(/check=on/, 'input[type=checkbox] field was submitted');
test.assertUrlMatch(/choice=no/, 'input[type=radio] field was submitted');
test.assertUrlMatch(/topic=bar/, 'select field was submitted');
test.assertUrlMatch(/strange=very/, 'strangely typed input field was submitted');
}
casper.test.begin('fill() & fillNames() tests', 15, function(test) {
casper.test.begin('fill() & fillNames() tests', 16, function(test) {
var fpath = fs.pathJoin(phantom.casperPath, 'README.md');
casper.start('tests/site/form.html', function() {
......@@ -47,7 +48,8 @@ casper.test.begin('fill() & fillNames() tests', 15, function(test) {
choice: 'no',
topic: 'bar',
file: fpath,
'checklist[]': ['1', '3']
'checklist[]': ['1', '3'],
strange: "very"
});
testFormValues(test);
test.assertEvalEquals(function() {
......@@ -62,7 +64,7 @@ casper.test.begin('fill() & fillNames() tests', 15, function(test) {
});
});
casper.test.begin('fillSelectors() tests', 15, function(test) {
casper.test.begin('fillSelectors() tests', 16, function(test) {
var fpath = fs.pathJoin(phantom.casperPath, 'README.md');
casper.start('tests/site/form.html', function() {
......@@ -74,7 +76,8 @@ casper.test.begin('fillSelectors() tests', 15, function(test) {
"input[name='choice']": 'no',
"select[name='topic']": 'bar',
"input[name='file']": fpath,
"input[name='checklist[]']": ['1', '3']
"input[name='checklist[]']": ['1', '3'],
"input[name='strange']": "very"
});
testFormValues(test);
test.assertEvalEquals(function() {
......@@ -89,7 +92,7 @@ casper.test.begin('fillSelectors() tests', 15, function(test) {
});
});
casper.test.begin('fillXPath() tests', 14, function(test) {
casper.test.begin('fillXPath() tests', 15, function(test) {
casper.start('tests/site/form.html', function() {
this.fillXPath('form[action="result.html"]', {
'//input[@name="email"]': 'chuck@norris.com',
......@@ -98,7 +101,8 @@ casper.test.begin('fillXPath() tests', 14, function(test) {
'//input[@name="check"]': true,
'//input[@name="choice"]': 'no',
'//select[@name="topic"]': 'bar',
'//input[@name="checklist[]"]': ['1', '3']
'//input[@name="checklist[]"]': ['1', '3'],
'//input[@name="strange"]': "very"
});
testFormValues(test);
// note: file inputs cannot be filled using XPath
......@@ -173,7 +177,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
choice: 'no',
topic: 'bar',
file: fpath,
'checklist[]': ['1', '3']
'checklist[]': ['1', '3'],
strange: "very"
});
});
casper.then(function() {
......@@ -187,7 +192,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
"password": "chuck",
"submit": "submit",
"language": "english",
"topic": "bar"
"topic": "bar",
"strange": "very"
}, 'Casper.getFormValues() retrieves filled values');
});
casper.then(function() {
......@@ -200,7 +206,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
choice: 'yes',
topic: 'bar',
file: fpath,
'checklist[]': ['1', '3']
'checklist[]': ['1', '3'],
strange: "very"
});
});
casper.then(function() {
......@@ -214,7 +221,8 @@ casper.test.begin('getFormValues() tests', 2, function(test) {
"password": "chuck",
"language": "english",
"submit": "submit",
"topic": "bar"
"topic": "bar",
"strange": "very"
}, 'Casper.getFormValues() correctly retrieves values from radio inputs regardless of order');
});
casper.run(function() {
......