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
33f335a6
...
33f335a6d5b433665aeaf5c01fd74a3b8c26be91
authored
2011-11-30 10:23:16 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixed checkbox list filling, added tests
1 parent
61c69bda
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
14 deletions
casper.js
tests/run.js
tests/site/form.html
casper.js
View file @
33f335a
...
...
@@ -1061,6 +1061,7 @@
path
:
err
.
path
});
}
else
{
this
.
log
(
err
,
"error"
);
throw
err
;
}
}
...
...
@@ -1187,20 +1188,16 @@
field
.
value
=
value
;
break
;
case
"checkbox"
:
if
(
fields
)
{
if
(
fields
.
length
>
1
)
{
var
values
=
value
;
if
(
!
Array
.
isArray
(
values
))
{
values
=
[
values
];
}
Array
.
prototype
.
forEach
.
call
(
fields
,
function
(
e
)
{
if
(
values
.
indexOf
(
e
.
value
)
!==
-
1
)
{
e
.
setAttribute
(
'checked'
,
'checked'
);
}
else
{
e
.
removeAttribute
(
'checked'
);
}
Array
.
prototype
.
forEach
.
call
(
fields
,
function
(
f
)
{
f
.
checked
=
values
.
indexOf
(
f
.
value
)
!==
-
1
?
true
:
false
;
});
}
else
{
field
.
setAttribute
(
'checked'
,
value
?
"checked"
:
""
)
;
field
.
checked
=
value
?
true
:
false
;
}
break
;
case
"file"
:
...
...
tests/run.js
View file @
33f335a
...
...
@@ -104,12 +104,13 @@ casper.then(function(self) {
self
.
test
.
assertTitle
(
'CasperJS test form'
,
'Casper.click() casper can click on a text link and react when it is loaded 2/2'
);
self
.
test
.
comment
(
'filling a form'
);
self
.
fill
(
'form[action="result.html"]'
,
{
email
:
'chuck@norris.com'
,
content
:
'Am watching thou'
,
check
:
true
,
choice
:
'no'
,
topic
:
'bar'
,
file
:
phantom
.
libraryPath
+
'/README.md'
email
:
'chuck@norris.com'
,
content
:
'Am watching thou'
,
check
:
true
,
choice
:
'no'
,
topic
:
'bar'
,
file
:
phantom
.
libraryPath
+
'/README.md'
,
'checklist[]'
:
[
'1'
,
'3'
]
});
self
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="email"]'
).
value
;
...
...
@@ -132,6 +133,11 @@ casper.then(function(self) {
self
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="file"]'
).
files
.
length
===
1
;
},
true
,
'Casper.fill() can select a file to upload'
);
self
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="checklist[]"][value="1"]'
).
checked
&&
!
document
.
querySelector
(
'input[name="checklist[]"][value="2"]'
).
checked
&&
document
.
querySelector
(
'input[name="checklist[]"][value="3"]'
).
checked
},
true
,
'Casper.fill() can fill a list of checkboxes'
);
self
.
click
(
'input[type="submit"]'
);
});
...
...
tests/site/form.html
View file @
33f335a
...
...
@@ -16,6 +16,9 @@
<input
type=
"radio"
name=
"choice"
value=
"yes"
/>
<input
type=
"radio"
name=
"choice"
value=
"no"
/>
<input
type=
"file"
name=
"file"
/>
<input
type=
"checkbox"
name=
"checklist[]"
value=
"1"
/>
<input
type=
"checkbox"
name=
"checklist[]"
value=
"2"
/>
<input
type=
"checkbox"
name=
"checklist[]"
value=
"3"
/>
<input
type=
"submit"
/>
</form>
</body>
...
...
Please
register
or
sign in
to post a comment