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
656f2d10
...
656f2d103b0ee40202032447cf5b4707ff2eaa23
authored
2013-01-10 17:09:07 -0800
by
Philip Hansen
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refs #350 - Added method and tests for waitForSelectorTextChange()
1 parent
6ea9a841
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletions
modules/casper.js
tests/site/waitFor.html
tests/suites/casper/wait.js
modules/casper.js
View file @
656f2d1
...
...
@@ -1852,6 +1852,26 @@ Casper.prototype.waitForText = function(text, then, onTimeout, timeout) {
};
/**
* Waits until the text on an element matching the provided DOM CSS3/XPath selector
* is changed to a different value.
*
* @param String selector A DOM CSS3/XPath selector
* @param Function then The next step to preform (optional)
* @param Function onTimeout A callback function to call on timeout (optional)
* @param Number timeout The max amount of time to wait, in milliseconds (optional)
* @return Casper
*/
Casper
.
prototype
.
waitForSelectorTextChange
=
function
(
selector
,
then
,
onTimeout
,
timeout
)
{
"user strict"
;
this
.
checkStarted
();
timeout
=
timeout
?
timeout
:
this
.
options
.
waitTimeout
;
var
currentSelectorText
=
this
.
fetchText
(
selector
);
return
this
.
waitFor
(
function
_check
()
{
return
currentSelectorText
!=
this
.
fetchText
(
selector
);
},
then
,
onTimeout
,
timeout
);
};
/**
* Waits until an element matching the provided DOM CSS3/XPath selector does not
* exist in the remote DOM to process a next step.
*
...
...
tests/site/waitFor.html
View file @
656f2d1
...
...
@@ -11,11 +11,15 @@
<li>
two
</li>
<li>
three
</li>
</ul>
<div
id=
"textChange"
>
Loading...
</div>
<script>
setTimeout
(
function
()
{
var
li
=
document
.
createElement
(
'li'
)
li
.
appendChild
(
document
.
createTextNode
(
'four'
));
document
.
querySelector
(
'ul'
).
appendChild
(
li
);
document
.
getElementById
(
'textChange'
).
innerHTML
=
'Done'
;
},
500
);
</script>
</body>
...
...
tests/suites/casper/wait.js
View file @
656f2d1
/*global casper*/
/*jshint strict:false*/
casper
.
test
.
begin
(
'wait*() tests'
,
3
,
function
(
test
)
{
casper
.
test
.
begin
(
'wait*() tests'
,
4
,
function
(
test
)
{
var
waitStart
;
casper
.
start
(
'tests/site/index.html'
,
function
()
{
...
...
@@ -30,6 +30,12 @@ casper.test.begin('wait*() tests', 3, function(test) {
test
.
fail
(
'Casper.waitForText() can wait for text'
);
});
casper
.
thenOpen
(
'tests/site/waitFor.html'
).
waitForSelectorTextChange
(
'#textChange'
,
function
()
{
test
.
pass
(
'Casper.waitForSelectorTextChange() can wait for text on a selector to change'
);
},
function
()
{
test
.
fail
(
'Casper.waitForSelectorTextChange() can wait for text on a selector to change'
);
})
casper
.
run
(
function
()
{
test
.
done
();
});
...
...
Please
register
or
sign in
to post a comment