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
626c0455
...
626c0455daf6a808bab5cf01d5eccd6a1b6ea9f1
authored
2012-07-29 16:00:00 -0400
by
Andrew Childs
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
AC: Add assertField to tester module.
1 parent
b766e4de
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
0 deletions
modules/tester.js
tests/site/index.html
tests/suites/tester.js
modules/tester.js
View file @
626c045
...
...
@@ -220,6 +220,30 @@ var Tester = function Tester(casper, options) {
};
/**
* Asserts that a given input field has the provided value.
*
* @param String input_name The name attribute of the input element
* @param String expected_value The expected value of the input element
* @param String message Test description
* @return Object An assertion result object
*/
this
.
assertField
=
function
assertField
(
input_name
,
expected_value
,
message
)
{
var
actual_value
=
casper
.
evaluate
(
function
(
input_name
)
{
var
input
=
document
.
querySelector
(
'input[name="'
+
input_name
+
'"]'
);
return
input
?
input
.
value
:
null
;
},
{
input_name
:
input_name
});
return
this
.
assert
(
this
.
testEquals
(
actual_value
,
expected_value
),
message
,
{
type
:
'assertField'
,
standard
:
f
(
'%s input field has the value %s'
,
this
.
colorize
(
input_name
,
'COMMENT'
),
this
.
colorize
(
expected_value
,
'COMMENT'
)),
values
:
{
input_name
:
input_name
,
actual_value
:
actual_value
,
expected_value
:
expected_value
}
});
};
/**
* Asserts that an element matching the provided selector expression exists in
* remote DOM.
*
...
...
tests/site/index.html
View file @
626c045
...
...
@@ -13,5 +13,6 @@
<li>
two
</li>
<li>
three
</li>
</ul>
<input
type=
"text"
name=
"dummy_name"
value=
"dummy_value"
/>
</body>
</html>
...
...
tests/suites/tester.js
View file @
626c045
...
...
@@ -45,6 +45,9 @@ var expected = [
t
.
assertEquals
(
files
,
expected
,
'findTestFiles() find test files and sort them'
);
casper
.
thenOpen
(
'tests/site/index.html'
,
function
()
{
t
.
comment
(
'Tester.assertField()'
);
t
.
assertField
(
'dummy_name'
,
'dummy_value'
,
'Tester.assertField() works as expected'
);
t
.
comment
(
'Tester.assertTextExists()'
);
t
.
assertTextExists
(
'form'
,
'Tester.assertTextExists() checks that page body contains text'
);
});
...
...
Please
register
or
sign in
to post a comment