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
7c2137eb
...
7c2137eb036307d8f2cafec2758639f26b092dd1
authored
2012-10-24 13:33:06 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refs #259 - things were harder than initially expected
1 parent
a04d47a8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
6 deletions
docs
modules/clientutils.js
tests/suites/tester.js
docs
@
3b87b13e
Subproject commit
4826e2bb9a2ecbaf0511b6aec0fd3b68d566e23b
Subproject commit
3b87b13e5849f5c8d7555c9a5fc6712eda5aa7a8
...
...
modules/clientutils.js
View file @
7c2137e
...
...
@@ -408,15 +408,37 @@
return
nodes
;
};
/**
* Retrieves the value of a form field.
*
* @param String inputName The for input name attr value
* @return Mixed
*/
this
.
getFieldValue
=
function
getFieldValue
(
inputName
)
{
var
inputs
=
this
.
findAll
(
'[name="'
+
inputName
+
'"]'
);
var
inputs
=
this
.
findAll
(
'[name="'
+
inputName
+
'"]'
)
,
type
;
switch
(
inputs
.
length
)
{
case
0
:
return
null
;
case
1
:
return
inputs
[
0
].
value
;
//this.log(inputs[0].nodeName.toLowerCase(), "error");
var
input
=
inputs
[
0
];
try
{
type
=
input
.
getAttribute
(
'type'
).
toLowerCase
();
}
catch
(
e
)
{
type
=
'other'
;
}
if
([
'checkbox'
,
'radio'
].
indexOf
(
type
)
===
-
1
)
{
return
input
.
value
;
}
// single checkbox or… radio button (weird, I know)
if
(
input
.
hasAttribute
(
'value'
))
{
return
input
.
checked
?
input
.
getAttribute
(
'value'
)
:
undefined
;
}
else
{
return
input
.
checked
;
}
break
;
default
:
var
type
=
inputs
[
0
].
getAttribute
(
'type'
).
toLowerCase
();
type
=
inputs
[
0
].
getAttribute
(
'type'
).
toLowerCase
();
if
(
type
===
'radio'
)
{
var
value
;
[].
forEach
.
call
(
inputs
,
function
(
radio
)
{
...
...
tests/suites/tester.js
View file @
7c2137e
...
...
@@ -97,11 +97,12 @@ casper.then(function() {
casper
.
thenOpen
(
'tests/site/form.html'
,
function
()
{
t
.
comment
(
'Tester.assertField()'
);
t
.
comment
(
'1. Fill inputs'
);
var
fpath
=
phantom
.
libraryPath
+
'/README.md'
;
this
.
fill
(
'form[action="result.html"]'
,
{
'email'
:
'chuck@norris.com'
,
'content'
:
'Am watching thou'
,
'check'
:
'on'
,
'check'
:
true
,
'choice'
:
'no'
,
'topic'
:
'bar'
,
'file'
:
fpath
,
...
...
@@ -109,13 +110,33 @@ casper.thenOpen('tests/site/form.html', function() {
});
t
.
assertField
(
'email'
,
'chuck@norris.com'
,
'Tester.assertField() works as expected with inputs'
);
t
.
assertField
(
'content'
,
'Am watching thou'
,
'Tester.assertField() works as expected with textarea'
);
t
.
assertField
(
'check'
,
'on'
,
'Tester.assertField() works as expected with checkboxes'
);
t
.
assertField
(
'check'
,
true
,
'Tester.assertField() works as expected with checkboxes'
);
t
.
assertField
(
'choice'
,
'no'
,
'Tester.assertField() works as expected with radios'
);
t
.
assertField
(
'topic'
,
'bar'
,
'Tester.assertField() works as expected with selects'
);
t
.
assertField
(
'file'
,
'C:\\fakepath\\README.md'
,
'Tester.assertField() works as expected with file inputs'
);
t
.
assertField
(
'checklist[]'
,
[
'1'
,
'3'
],
'Tester.assertField() works as expected with check lists'
);
});
casper
.
reload
(
function
()
{
t
.
comment
(
'2. Unfill inputs'
);
this
.
fill
(
'form[action="result.html"]'
,
{
'email'
:
''
,
'content'
:
''
,
'check'
:
false
,
'choice'
:
''
,
'topic'
:
''
,
'file'
:
''
,
'checklist[]'
:
[]
});
t
.
assertField
(
'email'
,
''
,
'Tester.assertField() works as expected with inputs'
);
t
.
assertField
(
'content'
,
''
,
'Tester.assertField() works as expected with textarea'
);
t
.
assertField
(
'check'
,
false
,
'Tester.assertField() works as expected with checkboxes'
);
t
.
assertField
(
'choice'
,
null
,
'Tester.assertField() works as expected with radios'
);
t
.
assertField
(
'topic'
,
'foo'
,
'Tester.assertField() works as expected with selects'
);
t
.
assertField
(
'file'
,
''
,
'Tester.assertField() works as expected with file inputs'
);
t
.
assertField
(
'checklist[]'
,
[],
'Tester.assertField() works as expected with check lists'
);
});
casper
.
then
(
function
()
{
t
.
comment
(
'Tester.getFailures()'
);
t
.
assertEquals
(
typeof
t
.
getFailures
().
length
,
"number"
,
"Tester.getFailures() works as expected"
);
...
...
Please
register
or
sign in
to post a comment