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
067b6dcf
...
067b6dcf9e45d9e0e08f25cc3e9fc039ea53ae55
authored
2013-01-02 21:33:59 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Tester.assertElementCount()
1 parent
41710652
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletions
modules/tester.js
tests/suites/tester/assert.js
modules/tester.js
View file @
067b6dc
...
...
@@ -281,6 +281,35 @@ Tester.prototype.assertNotEquals = function assertNotEquals(subject, shouldnt, m
};
/**
* Asserts that a selector expression matches n elements.
*
* @param Mixed selector A selector expression
* @param Number count Expected number of matching elements
* @param String message Test description (Optional)
* @return Object An assertion result object
*/
Tester
.
prototype
.
assertElementCount
=
function
assertElementCount
(
selector
,
count
,
message
)
{
"use strict"
;
if
(
!
utils
.
isNumber
(
count
)
||
count
<
0
)
{
throw
new
CasperError
(
'assertElementCount() needs a positive integer count'
);
}
return
this
.
assert
(
this
.
casper
.
evaluate
(
function
(
selector
)
{
try
{
return
__utils__
.
findAll
(
selector
).
length
;
}
catch
(
e
)
{
return
-
1
;
}
},
selector
)
===
count
,
message
,
{
type
:
"assertElementCount"
,
standard
:
f
(
"%d matching element(s) found"
,
count
),
values
:
{
selector
:
selector
,
count
:
count
}
});
};
/**
* Asserts that a code evaluation in remote DOM resolves to true.
*
* @param Function fn A function to be evaluated in remote DOM
...
...
tests/suites/tester/assert.js
View file @
067b6dc
...
...
@@ -2,7 +2,7 @@
/*jshint strict:false maxstatements:99*/
var
fs
=
require
(
'fs'
);
casper
.
test
.
begin
(
'Common assertions tests'
,
4
0
,
function
(
test
)
{
casper
.
test
.
begin
(
'Common assertions tests'
,
4
3
,
function
(
test
)
{
casper
.
start
(
'tests/site/index.html'
,
function
()
{
test
.
assertTextExists
(
'form'
,
'Tester.assertTextExists() checks that page body contains text'
);
test
.
assertTextExist
(
'form'
,
'Tester.assertTextExist() checks that page body contains text [alias]'
);
...
...
@@ -29,6 +29,9 @@ casper.test.begin('Common assertions tests', 40, function(test) {
test
.
assertEvalEqual
(
function
()
{
return
42
;
},
42
,
'Tester.assertEvalEqual() works as expected [alias]'
);
test
.
assertElementCount
(
'ul'
,
1
,
'Tester.assertElementCount() works as expected'
);
test
.
assertElementCount
(
'li'
,
3
,
'Tester.assertElementCount() works as expected'
);
test
.
assertElementCount
(
'address'
,
0
,
'Tester.assertElementCount() works as expected'
);
test
.
assertExists
(
'body'
,
'Tester.assertExists() works as expected'
);
test
.
assertExist
(
'body'
,
'Tester.assertExist() works as expected [alias]'
);
test
.
assertSelectorExists
(
'body'
,
'Tester.assertSelectorExists() works as expected [alias]'
);
...
...
Please
register
or
sign in
to post a comment