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
b025ea98
...
b025ea98f9cc7231d2f2b2ee1516c77f07fff4e0
authored
2011-11-30 08:43:10 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper.options.onAlert() callback
1 parent
4dd4b736
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
casper.js
tests/run.js
tests/site/alert.html
casper.js
View file @
b025ea9
...
...
@@ -45,6 +45,7 @@
faultTolerant
:
true
,
logLevel
:
"error"
,
httpStatusHandlers
:
{},
onAlert
:
null
,
onDie
:
null
,
onError
:
null
,
onLoadError
:
null
,
...
...
@@ -1661,6 +1662,12 @@
}
else
{
page
=
require
(
'webpage'
).
create
();
}
page
.
onAlert
=
function
(
message
)
{
casper
.
log
(
'[alert] '
+
message
,
"info"
,
"remote"
);
if
(
isType
(
casper
.
options
.
onAlert
,
"function"
))
{
casper
.
options
.
onAlert
.
call
(
casper
,
casper
,
message
);
}
};
page
.
onConsoleMessage
=
function
(
msg
)
{
var
level
=
"info"
,
test
=
/^
\[
casper:
(\w
+
)\]\s?(
.*
)
/
.
exec
(
msg
);
if
(
test
&&
test
.
length
===
3
)
{
...
...
tests/run.js
View file @
b025ea9
...
...
@@ -259,6 +259,16 @@ casper
})
;
// Casper.options.onAlert()
casper
.
then
(
function
(
self
)
{
self
.
options
.
onAlert
=
function
(
self
,
message
)
{
self
.
test
.
assertEquals
(
message
,
'plop'
,
'Casper.options.onAlert() can intercept an alert message'
);
};
});
casper
.
thenOpen
(
'tests/site/alert.html'
).
click
(
'button'
,
function
(
self
)
{
self
.
options
.
onAlert
=
null
;
});
// run suite
casper
.
run
(
function
(
self
)
{
casper
.
test
.
comment
(
'history'
);
...
...
tests/site/alert.html
0 → 100644
View file @
b025ea9
<!DOCTYPE html>
<html>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>
CasperJS test alert
</title>
</head>
<body>
<script>
alert
(
'plop'
)
</script>
</body>
</html>
Please
register
or
sign in
to post a comment