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
0fe5118d
...
0fe5118df365971ef91e486d3265e17c8872f313
authored
2012-09-23 16:22:01 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge remote-tracking branch 'andrewchilds/ac/added-assertions' into pr-197
2 parents
8d4083b9
637d7128
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
1 deletions
modules/tester.js
tests/site/index.html
tests/suites/tester.js
modules/tester.js
View file @
0fe5118
...
...
@@ -238,6 +238,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.
*
...
...
@@ -372,7 +396,7 @@ var Tester = function Tester(casper, options) {
};
/**
* Asserts that given text exits in the document body.
* Asserts that given text exi
s
ts in the document body.
*
* @param String text Text to be found
* @param String message Test description
...
...
@@ -392,6 +416,46 @@ var Tester = function Tester(casper, options) {
};
/**
* Asserts that given text exists in the provided selector.
*
* @param String selector Selector expression
* @param String text Text to be found
* @param String message Test description
* @return Object An assertion result object
*/
this
.
assertSelectorHasText
=
function
assertSelectorHasText
(
selector
,
text
,
message
)
{
var
textFound
=
casper
.
fetchText
(
selector
).
indexOf
(
text
)
!==
-
1
;
return
this
.
assert
(
textFound
,
message
,
{
type
:
"assertTextInSelector"
,
standard
:
f
(
'Found %s within the selector %s'
,
this
.
colorize
(
text
,
'COMMENT'
),
this
.
colorize
(
selector
,
'COMMENT'
)),
values
:
{
selector
:
selector
,
text
:
text
}
});
};
/**
* Asserts that given text does not exist in the provided selector.
*
* @param String selector Selector expression
* @param String text Text not to be found
* @param String message Test description
* @return Object An assertion result object
*/
this
.
assertSelectorDoesntHaveText
=
function
assertSelectorDoesntHaveText
(
selector
,
text
,
message
)
{
var
textFound
=
casper
.
fetchText
(
selector
).
indexOf
(
text
)
===
-
1
;
return
this
.
assert
(
textFound
,
message
,
{
type
:
"assertNoTextInSelector"
,
standard
:
f
(
'Did not find %s within the selector %s'
,
this
.
colorize
(
text
,
'COMMENT'
),
this
.
colorize
(
selector
,
'COMMENT'
)),
values
:
{
selector
:
selector
,
text
:
text
}
});
};
/**
* Asserts that title of the remote page equals to the expected one.
*
* @param String expected The expected title string
...
...
tests/site/index.html
View file @
0fe5118
...
...
@@ -13,5 +13,7 @@
<li>
two
</li>
<li>
three
</li>
</ul>
<input
type=
"text"
name=
"dummy_name"
value=
"dummy_value"
/>
<h1>
Title
</h1>
</body>
</html>
...
...
tests/suites/tester.js
View file @
0fe5118
...
...
@@ -45,8 +45,17 @@ 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'
);
t
.
comment
(
'Tester.assertSelectorHasText()'
);
t
.
assertSelectorHasText
(
'h1'
,
'Title'
,
'Tester.assertSelectorHasText() works as expected'
);
t
.
comment
(
'Tester.assertSelectorDoesntHaveText()'
);
t
.
assertSelectorDoesntHaveText
(
'h1'
,
'Subtitle'
,
'Tester.assertSelectorDoesntHaveText() works as expected'
);
});
casper
.
then
(
function
()
{
...
...
Please
register
or
sign in
to post a comment