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
3b6018f4
...
3b6018f4de9005894e6d911567b82efe76f4094e
authored
2013-11-03 15:03:22 -0800
by
Nathan Black
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Update tester to output tailored messages for waitFor.timeouts
1 parent
9bad6047
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
167 additions
and
13 deletions
modules/tester.js
tests/clitests/runtests.py
tests/clitests/tester/waitFor_timeout.js
modules/tester.js
View file @
3b6018f
...
...
@@ -164,15 +164,6 @@ var Tester = function Tester(casper, options) {
}
});
// casper events
this
.
casper
.
on
(
'error'
,
function
onCasperError
(
msg
,
backtrace
)
{
self
.
processPhantomError
(
msg
,
backtrace
);
});
this
.
casper
.
on
(
'waitFor.timeout'
,
function
onWaitForTimeout
(
timeout
)
{
this
.
warn
(
f
(
'wait timeout of %dms reached'
,
timeout
));
});
function
errorHandler
(
error
,
backtrace
)
{
self
.
casper
.
unwait
();
if
(
error
instanceof
Error
)
{
...
...
@@ -190,12 +181,46 @@ var Tester = function Tester(casper, options) {
}
catch
(
e
)
{}
self
.
uncaughtError
(
error
,
self
.
currentTestFile
,
line
,
backtrace
);
}
function
errorHandlerAndDone
(
error
,
backtrace
)
{
errorHandler
(
error
,
backtrace
);
self
.
done
();
}
// casper events
this
.
casper
.
on
(
'error'
,
function
onCasperError
(
msg
,
backtrace
)
{
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'
,
...
...
@@ -227,9 +252,7 @@ var Tester = function Tester(casper, options) {
throw
new
TimedOutError
(
f
(
"Timeout occured (%dms)"
,
timeout
));
};
this
.
casper
.
options
.
onWaitTimeout
=
function
test_onWaitTimeout
(
timeout
)
{
throw
new
TimedOutError
(
f
(
"Wait timeout occured (%dms)"
,
timeout
));
};
this
.
casper
.
options
.
onWaitTimeout
=
function
()
{};
};
// Tester class is an EventEmitter
...
...
tests/clitests/runtests.py
View file @
3b6018f
...
...
@@ -287,6 +287,21 @@ class TestCommandOutputTest(CasperExecTestBase):
],
failing
=
True
)
@timeout
(
20
)
def
test_waitFor_timeout
(
self
):
# using begin()
script_path
=
os
.
path
.
join
(
TEST_ROOT
,
'tester'
,
'waitFor_timeout.js'
)
self
.
assertCommandOutputContains
(
'test '
+
script_path
,
[
'"p.nonexistent" still did not exist in'
,
'"#encoded" did not have a text change in'
,
'"p[style]" never appeared in'
,
'/github
\
.com/ did not load in'
,
'/foobar/ did not pop up in'
,
'"Lorem ipsum" did not appear in the page in'
,
'return false'
,
'did not evaluate to something truthy in'
],
failing
=
True
)
@timeout
(
20
)
def
test_dubious_test
(
self
):
script_path
=
os
.
path
.
join
(
TEST_ROOT
,
'tester'
,
'dubious.js'
)
self
.
assertCommandOutputContains
(
'test '
+
script_path
,
[
...
...
tests/clitests/tester/waitFor_timeout.js
0 → 100644
View file @
3b6018f
/*global casper*/
/*jshint strict:false*/
casper
.
options
.
waitTimeout
=
500
;
casper
.
test
.
begin
(
'waitForSelector fails with expected message'
,
1
,
function
(
test
)
{
casper
.
start
(
'../site/waitFor.html'
);
casper
.
waitForSelector
(
'p.nonexistent'
,
function
()
{
throw
new
Error
(
'waitForSelector found something it should not have'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitWhileSelector fails with expected message'
,
1
,
function
(
test
)
{
casper
.
start
(
'../site/waitFor.html'
);
casper
.
waitForSelector
(
'#encoded'
);
casper
.
waitWhileSelector
(
'#encoded'
,
function
()
{
throw
new
Error
(
'waitWhileSelector thought something got removed when it did not'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitForSelectorTextChange fails with expected message'
,
1
,
function
(
test
)
{
casper
.
start
(
'../site/waitFor.html'
);
casper
.
waitForSelectorTextChange
(
'#encoded'
,
function
()
{
throw
new
Error
(
'waitForSelectorTextChange thought text changed when it did not'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitUntilVisible fails with expected message'
,
1
,
function
(
test
)
{
casper
.
start
(
'../site/waitFor.html'
);
casper
.
waitUntilVisible
(
'p[style]'
,
function
()
{
throw
new
Error
(
'waitUntilVisible falsely identified a hidden paragraph'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitWhileVisible fails with expected message'
,
1
,
function
(
test
)
{
casper
.
start
(
'../site/waitFor.html'
);
casper
.
waitWhileVisible
(
'img'
,
function
()
{
throw
new
Error
(
'waitWhileVisible thought something disappeared when it did not'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitForUrl fails with expected message'
,
1
,
function
(
test
)
{
casper
.
start
(
'../site/waitFor.html'
);
casper
.
waitForUrl
(
/github
\.
com/
,
function
()
{
throw
new
Error
(
'waitForUrl thought we actually navigated to GitHub'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitForPopup fails with expected message'
,
1
,
function
(
test
)
{
casper
.
start
(
'../site/waitFor.html'
);
casper
.
waitForPopup
(
/foobar/
,
function
()
{
throw
new
Error
(
'waitForPopup found something it should not have'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitForText fails with expected message'
,
1
,
function
(
test
)
{
casper
.
start
(
'../site/waitFor.html'
);
casper
.
waitForText
(
"Lorem ipsum"
,
function
()
{
throw
new
Error
(
'waitForText found something it should not have'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'waitFor fails with expected message'
,
1
,
function
(
test
)
{
casper
.
start
(
'../site/waitFor.html'
);
casper
.
waitFor
(
function
()
{
return
false
},
function
()
{
throw
new
Error
(
'waitFor fasely succeeded'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
\ No newline at end of file
Please
register
or
sign in
to post a comment