Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
2b185aac
...
2b185aac21600506388ba3b119cd8d1e49a7b69b
authored
2013-08-12 13:44:01 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #544 - treat any input tag type as valid when filling forms
1 parent
130e23f7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
29 deletions
modules/clientutils.js
tests/site/form.html
tests/suites/casper/formfill.js
modules/clientutils.js
View file @
2b185aa
...
...
@@ -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: "
+
typ
e
;
field
.
value
=
valu
e
;
break
;
}
break
;
...
...
tests/site/form.html
View file @
2b185aa
...
...
@@ -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>
...
...
tests/suites/casper/formfill.js
View file @
2b185aa
...
...
@@ -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'
,
1
5
,
function
(
test
)
{
casper
.
test
.
begin
(
'fill() & fillNames() tests'
,
1
6
,
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'
,
1
5
,
function
(
test
)
{
casper
.
test
.
begin
(
'fillSelectors() tests'
,
1
6
,
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'
,
1
4
,
function
(
test
)
{
casper
.
test
.
begin
(
'fillXPath() tests'
,
1
5
,
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
()
{
...
...
Please
register
or
sign in
to post a comment