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
637d7128
...
637d7128d47c17910e3ffa98188e34e4ab84dccd
authored
2012-07-29 18:12:00 -0400
by
Andrew Childs
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
AC: Add assertSelectorHasText and assertSelectorDoesntHaveText functions.
1 parent
626c0455
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
0 deletions
modules/tester.js
tests/site/index.html
tests/suites/tester.js
modules/tester.js
View file @
637d712
...
...
@@ -398,6 +398,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 @
637d712
...
...
@@ -14,5 +14,6 @@
<li>
three
</li>
</ul>
<input
type=
"text"
name=
"dummy_name"
value=
"dummy_value"
/>
<h1>
Title
</h1>
</body>
</html>
...
...
tests/suites/tester.js
View file @
637d712
...
...
@@ -50,6 +50,12 @@ casper.thenOpen('tests/site/index.html', function() {
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