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
3f07a5b3
...
3f07a5b39edc1f495c6e6376c28aa55308e1cbae
authored
2013-11-04 15:51:03 -0800
by
Nathan Black
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Handle wait timeouts in the callback and not the event to fix selftest failures.
1 parent
49ec2987
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
34 deletions
modules/casper.js
modules/tester.js
modules/casper.js
View file @
3f07a5b
...
...
@@ -2009,7 +2009,8 @@ Casper.prototype.waitDone = function waitDone() {
Casper
.
prototype
.
waitFor
=
function
waitFor
(
testFx
,
then
,
onTimeout
,
timeout
,
details
)
{
"use strict"
;
this
.
checkStarted
();
timeout
=
timeout
?
timeout
:
this
.
options
.
waitTimeout
;
timeout
=
timeout
||
this
.
options
.
waitTimeout
;
details
=
details
||
{
testFx
:
testFx
};
if
(
!
utils
.
isFunction
(
testFx
))
{
throw
new
CasperError
(
"waitFor() needs a test function"
);
}
...
...
@@ -2030,13 +2031,13 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, de
if
(
!
condition
)
{
self
.
log
(
"Casper.waitFor() timeout"
,
"warning"
);
var
onWaitTimeout
=
onTimeout
?
onTimeout
:
self
.
options
.
onWaitTimeout
;
self
.
emit
(
'waitFor.timeout'
,
timeout
,
details
||
{
testFx
:
testFx
}
);
self
.
emit
(
'waitFor.timeout'
,
timeout
,
details
);
clearInterval
(
interval
);
// refs #383
if
(
!
utils
.
isFunction
(
onWaitTimeout
))
{
throw
new
CasperError
(
'Invalid timeout function'
);
}
try
{
return
onWaitTimeout
.
call
(
self
,
timeout
);
return
onWaitTimeout
.
call
(
self
,
timeout
,
details
);
}
catch
(
error
)
{
self
.
emit
(
'waitFor.timeout.error'
,
error
);
}
finally
{
...
...
modules/tester.js
View file @
3f07a5b
...
...
@@ -192,35 +192,6 @@ var Tester = function Tester(casper, options) {
self
.
processPhantomError
(
msg
,
backtrace
);
});
this
.
casper
.
on
(
'waitFor.timeout'
,
function
onWaitForTimeout
(
timeout
,
details
)
{
var
message
=
f
(
"Wait timeout occured (%dms)"
,
timeout
);
details
=
details
||
{};
if
(
details
.
selector
)
{
message
=
f
(
details
.
waitWhile
?
'"%s" never went away in %dms'
:
'"%s" still did not exist in %dms'
,
details
.
selector
,
timeout
);
}
else
if
(
details
.
visible
)
{
message
=
f
(
details
.
waitWhile
?
'"%s" never disappeared in %dms'
:
'"%s" never appeared in %dms'
,
details
.
visible
,
timeout
);
}
else
if
(
details
.
url
||
details
.
resource
)
{
message
=
f
(
'%s did not load in %dms'
,
details
.
url
||
details
.
resource
,
timeout
);
}
else
if
(
details
.
popup
)
{
message
=
f
(
'%s did not pop up in %dms'
,
details
.
popup
,
timeout
);
}
else
if
(
details
.
text
)
{
message
=
f
(
'"%s" did not appear in the page in %dms'
,
details
.
text
,
timeout
);
}
else
if
(
details
.
selectorTextChange
)
{
message
=
f
(
'"%s" did not have a text change in %dms'
,
details
.
selectorTextChange
,
timeout
);
}
else
if
(
utils
.
isFunction
(
details
.
testFx
))
{
message
=
f
(
'"%s" did not evaluate to something truthy in %dms'
,
details
.
testFx
.
toString
(),
timeout
);
}
errorHandlerAndDone
(
new
TimedOutError
(
message
));
});
[
'wait.error'
,
'waitFor.timeout.error'
,
...
...
@@ -252,7 +223,35 @@ var Tester = function Tester(casper, options) {
throw
new
TimedOutError
(
f
(
"Timeout occured (%dms)"
,
timeout
));
};
this
.
casper
.
options
.
onWaitTimeout
=
function
()
{};
this
.
casper
.
options
.
onWaitTimeout
=
function
test_onWaitTimeout
(
timeout
,
details
)
{
/*jshint maxcomplexity:10*/
var
message
=
f
(
"Wait timeout occured (%dms)"
,
timeout
);
details
=
details
||
{};
if
(
details
.
selector
)
{
message
=
f
(
details
.
waitWhile
?
'"%s" never went away in %dms'
:
'"%s" still did not exist in %dms'
,
details
.
selector
,
timeout
);
}
else
if
(
details
.
visible
)
{
message
=
f
(
details
.
waitWhile
?
'"%s" never disappeared in %dms'
:
'"%s" never appeared in %dms'
,
details
.
visible
,
timeout
);
}
else
if
(
details
.
url
||
details
.
resource
)
{
message
=
f
(
'%s did not load in %dms'
,
details
.
url
||
details
.
resource
,
timeout
);
}
else
if
(
details
.
popup
)
{
message
=
f
(
'%s did not pop up in %dms'
,
details
.
popup
,
timeout
);
}
else
if
(
details
.
text
)
{
message
=
f
(
'"%s" did not appear in the page in %dms'
,
details
.
text
,
timeout
);
}
else
if
(
details
.
selectorTextChange
)
{
message
=
f
(
'"%s" did not have a text change in %dms'
,
details
.
selectorTextChange
,
timeout
);
}
else
if
(
utils
.
isFunction
(
details
.
testFx
))
{
message
=
f
(
'"%s" did not evaluate to something truthy in %dms'
,
details
.
testFx
.
toString
(),
timeout
);
}
errorHandlerAndDone
(
new
TimedOutError
(
message
));
};
};
// Tester class is an EventEmitter
...
...
@@ -880,7 +879,7 @@ Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, construct
standard
:
f
(
'Subject is instance of: "%s"'
,
constructor
.
name
),
values
:
{
subject
:
subject
,
constructorName
:
constructor
.
name
,
constructorName
:
constructor
.
name
}
});
};
...
...
Please
register
or
sign in
to post a comment