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
661c77ec
...
661c77ecc55453fbe8ef823d82d802b74bc52244
authored
2013-02-16 16:11:09 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #383, #369: waiting process not stopped on timeout reached
only in test mode.
1 parent
8c7d533f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
24 deletions
modules/casper.js
modules/tester.js
tests/suites/casper/wait.js
modules/casper.js
View file @
661c77e
...
...
@@ -1249,6 +1249,7 @@ Casper.prototype.reload = function reload(then) {
if
(
utils
.
isFunction
(
then
))
{
this
.
then
(
this
.
createStep
(
then
));
}
return
this
;
};
/**
...
...
@@ -1758,6 +1759,7 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
var
start
=
new
Date
().
getTime
();
var
condition
=
false
;
var
interval
=
setInterval
(
function
_check
(
self
,
testFx
,
timeout
,
onTimeout
)
{
/*jshint maxstatements:20*/
if
((
new
Date
().
getTime
()
-
start
<
timeout
)
&&
!
condition
)
{
condition
=
testFx
.
call
(
self
,
self
);
return
;
...
...
@@ -1767,17 +1769,17 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
self
.
log
(
"Casper.waitFor() timeout"
,
"warning"
);
var
onWaitTimeout
=
onTimeout
?
onTimeout
:
self
.
options
.
onWaitTimeout
;
self
.
emit
(
'waitFor.timeout'
,
timeout
,
onWaitTimeout
);
clearInterval
(
interval
);
// refs #383
if
(
!
utils
.
isFunction
(
onWaitTimeout
))
{
throw
new
CasperError
(
'Invalid timeout function, exiting.'
);
}
onWaitTimeout
.
call
(
self
,
timeout
);
}
else
{
self
.
log
(
f
(
"waitFor() finished in %dms."
,
new
Date
().
getTime
()
-
start
),
"info"
);
if
(
then
)
{
self
.
then
(
then
);
throw
new
CasperError
(
'Invalid timeout function'
);
}
return
onWaitTimeout
.
call
(
self
,
timeout
);
}
self
.
log
(
f
(
"waitFor() finished in %dms."
,
new
Date
().
getTime
()
-
start
),
"info"
);
clearInterval
(
interval
);
if
(
then
)
{
self
.
then
(
then
);
}
},
100
,
this
,
testFx
,
timeout
,
onTimeout
);
});
};
...
...
modules/tester.js
View file @
661c77e
...
...
@@ -143,8 +143,16 @@ var Tester = function Tester(casper, options) {
// casper events
this
.
casper
.
on
(
'error'
,
function
onCasperError
(
msg
,
backtrace
)
{
this
.
test
.
fail
(
msg
,
{
type
:
'error'
,
var
type
=
'error'
,
message
=
msg
,
match
=
/^
(\w
+
)
Error:
(
.*
)
/
.
exec
(
msg
);
if
(
match
)
{
type
=
match
[
1
].
toLowerCase
();
message
=
match
[
2
];
}
if
(
type
!==
'assertion'
)
{
return
this
.
test
.
uncaughtError
(
msg
,
this
.
currentTestFile
,
null
,
backtrace
);
}
this
.
test
.
fail
(
message
,
{
type
:
type
,
doThrow
:
false
,
values
:
{
stack
:
backtrace
...
...
@@ -1173,8 +1181,11 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) {
style
=
'GREEN_BAR'
;
}
result
=
f
(
'%s %s tests executed in %ss, %d passed, %d failed.'
,
statusText
,
total
,
utils
.
ms2seconds
(
this
.
suiteResults
.
calculateDuration
()),
passed
,
failed
);
statusText
,
total
,
utils
.
ms2seconds
(
this
.
suiteResults
.
calculateDuration
()),
passed
,
failed
);
}
this
.
casper
.
echo
(
result
,
style
,
this
.
options
.
pad
);
if
(
failed
>
0
)
{
...
...
@@ -1437,7 +1448,7 @@ TestSuiteResult.prototype.getAllResults = function getAllResults() {
TestSuiteResult
.
prototype
.
calculateDuration
=
function
calculateDuration
()
{
"use strict"
;
return
this
.
getAllResults
().
map
(
function
(
result
)
{
return
result
.
time
;
return
~~
result
.
time
;
}).
reduce
(
function
add
(
a
,
b
)
{
return
a
+
b
;
},
0
);
...
...
tests/suites/casper/wait.js
View file @
661c77e
/*global casper*/
/*jshint strict:false*/
casper
.
test
.
begin
(
'wait
*() tests'
,
4
,
function
(
test
)
{
casper
.
test
.
begin
(
'wait
() tests'
,
1
,
function
(
test
)
{
var
waitStart
;
casper
.
start
(
'tests/site/index.html'
,
function
()
{
...
...
@@ -12,25 +12,81 @@ casper.test.begin('wait*() tests', 4, function(test) {
'Casper.wait() can wait for a given amount of time'
);
});
casper
.
thenOpen
(
'tests/site/waitFor.html'
,
function
()
{
this
.
waitFor
(
function
()
{
return
this
.
evaluate
(
function
()
{
return
document
.
querySelectorAll
(
'li'
).
length
===
4
;
});
},
function
()
{
test
.
pass
(
'Casper.waitFor() can wait for something to happen'
);
},
function
()
{
test
.
fail
(
'Casper.waitFor() can wait for something to happen'
);
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitFor() tests'
,
2
,
function
(
test
)
{
casper
.
start
(
'tests/site/waitFor.html'
);
casper
.
waitFor
(
function
()
{
return
this
.
evaluate
(
function
()
{
return
document
.
querySelectorAll
(
'li'
).
length
===
4
;
});
},
function
()
{
test
.
pass
(
'Casper.waitFor() can wait for something to happen'
);
},
function
()
{
test
.
fail
(
'Casper.waitFor() can wait for something to happen'
);
});
casper
.
reload
().
waitFor
(
function
(){
return
false
;
},
function
()
{
test
.
fail
(
'waitFor() processes onTimeout callback'
);
},
function
()
{
test
.
pass
(
'waitFor() processes onTimeout callback'
);
},
1000
);
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitForResource() tests'
,
2
,
function
(
test
)
{
casper
.
start
(
'tests/site/waitFor.html'
);
casper
.
waitForResource
(
'phantom.png'
,
function
()
{
test
.
pass
(
'Casper.waitForResource() waits for a resource'
);
},
function
()
{
test
.
fail
(
'Casper.waitForResource() waits for a resource'
);
});
casper
.
reload
().
waitForResource
(
/phantom
\.
png$/
,
function
()
{
test
.
pass
(
'Casper.waitForResource() waits for a resource using RegExp'
);
},
function
()
{
test
.
fail
(
'Casper.waitForResource() waits for a resource using RegExp'
);
});
casper
.
thenOpen
(
'tests/site/waitFor.html'
).
waitForText
(
'<li>four</li>'
,
function
()
{
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitForSelector() tests'
,
1
,
function
(
test
)
{
casper
.
start
(
'tests/site/waitFor.html'
);
casper
.
waitForSelector
(
'li:nth-child(4)'
,
function
()
{
test
.
pass
(
'Casper.waitForSelector() waits for a selector to exist'
);
},
function
()
{
test
.
fail
(
'Casper.waitForSelector() waits for a selector to exist'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitForText() tests'
,
2
,
function
(
test
)
{
casper
.
start
(
'tests/site/waitFor.html'
);
casper
.
waitForText
(
'<li>four</li>'
,
function
()
{
test
.
pass
(
'Casper.waitForText() can wait for text'
);
},
function
()
{
test
.
fail
(
'Casper.waitForText() can wait for text'
);
});
casper
.
thenOpen
(
'tests/site/waitFor.html'
).
waitForText
(
/four/i
,
function
()
{
casper
.
reload
(
).
waitForText
(
/four/i
,
function
()
{
this
.
test
.
pass
(
'Casper.waitForText() can wait for regexp'
);
},
function
()
{
this
.
test
.
fail
(
'Casper.waitForText() can wait for regexp'
);
...
...
@@ -40,3 +96,17 @@ casper.test.begin('wait*() tests', 4, function(test) {
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitUntilVisible() tests'
,
1
,
function
(
test
)
{
casper
.
start
(
'tests/site/waitFor.html'
);
casper
.
waitUntilVisible
(
'li:nth-child(4)'
,
function
()
{
test
.
pass
(
'Casper.waitUntilVisible() waits for a selector being visible'
);
},
function
()
{
test
.
fail
(
'Casper.waitUntilVisible() waits for a selector being visible'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
...
...
Please
register
or
sign in
to post a comment