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
db638037
...
db638037de2ad908a07033fe41e46db1af153eeb
authored
2012-11-28 15:48:21 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper.getFormValues()
1 parent
8ec3e4e2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
1 deletions
CHANGELOG.md
docs
modules/casper.js
modules/clientutils.js
tests/suites/casper/formfill.js
CHANGELOG.md
View file @
db63803
...
...
@@ -33,6 +33,7 @@ casper.evaluate(function(a, b) {
-
fixed
[
#282
](
https://github.com/n1k0/casperjs/issues/282
)
- added support for remote client scripts loading with a new
`remoteScripts`
casper option
-
merged
[
#290
](
https://github.com/n1k0/casperjs/issues/#290
)
- add a simplistic RPM spec file to make it easier to (un)install casperjs
-
fixed
`Casper.die()`
and
`Casper.evaluateOrDie()`
were not printing the error onto the console
-
added
[
`Casper.getFormValues()`
](
http://casperjs.org/api.html#casper.getFormValues
)
to check for the field values of a given form
-
added
[
`Tester.assertTextDoesntExist()`
](
http://casperjs.org/api.html#tester.assertTextDoesntExist
)
-
added
`Tester.assertFalse()`
as an alias of
`Tester.assertNot()`
-
added
`page.resource.requested`
and
`page.resource.received`
events
...
...
docs
@
3b2e8742
Subproject commit
cd0d5fc3efd4279e0ac4062d012cb16d77cbc708
Subproject commit
3b2e87424f41b90efe734e3b64fdf1517f2fb39c
...
...
modules/casper.js
View file @
db63803
...
...
@@ -852,6 +852,23 @@ Casper.prototype.getElementsBounds = function getElementBounds(selector) {
};
/**
* Retrieves a given form all of its field values.
*
* @param String selector A DOM CSS3/XPath selector
* @return Object
*/
Casper
.
prototype
.
getFormValues
=
function
(
selector
)
{
"use strict"
;
this
.
checkStarted
();
if
(
!
this
.
exists
(
selector
))
{
throw
new
CasperError
(
f
(
'Form matching selector "%s" not found'
,
selector
));
}
return
this
.
evaluate
(
function
(
selector
)
{
return
__utils__
.
getFormValues
(
selector
);
},
selector
);
};
/**
* Retrieves global variable.
*
* @param String name The name of the global variable to retrieve
...
...
modules/clientutils.js
View file @
db63803
...
...
@@ -469,6 +469,25 @@
};
/**
* Retrieves a given form all of its field values.
*
* @param String selector A DOM CSS3/XPath selector
* @return Object
*/
this
.
getFormValues
=
function
getFormValues
(
selector
)
{
var
form
=
__utils__
.
findOne
(
selector
);
var
values
=
{};
var
self
=
this
;
[].
forEach
.
call
(
form
.
elements
,
function
(
element
)
{
var
name
=
element
.
getAttribute
(
'name'
);
if
(
name
)
{
values
[
name
]
=
self
.
getFieldValue
(
name
);
}
});
return
values
;
};
/**
* Logs a message. Will format the message a way CasperJS will be able
* to log phantomjs side.
*
...
...
tests/suites/casper/formfill.js
View file @
db63803
...
...
@@ -41,6 +41,23 @@ casper.start('tests/site/form.html', function() {
!
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'
);
});
casper
.
then
(
function
()
{
this
.
test
.
comment
(
'Casper.getFormValues()'
);
this
.
test
.
assertEquals
(
this
.
getFormValues
(
'form'
),
{
"check"
:
true
,
"checklist[]"
:
[
"1"
,
"3"
],
"choice"
:
"no"
,
"content"
:
"Am watching thou"
,
"email"
:
"chuck@norris.com"
,
"file"
:
"C:\\fakepath\\README.md"
,
"password"
:
"chuck"
,
"submit"
:
"submit"
,
"topic"
:
"bar"
},
'Casper.getFormValues() retrieves filled values'
);
this
.
test
.
comment
(
'submitting form'
);
this
.
click
(
'input[type="submit"]'
);
});
...
...
Please
register
or
sign in
to post a comment