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
a19f2978
...
a19f2978076a6a92352256979ef46f7d392adc9f
authored
2012-04-30 13:29:49 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
closes #97 - De-anonymize all functions
1 parent
a7da3f0b
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
111 additions
and
111 deletions
modules/casper.js
modules/cli.js
modules/clientutils.js
modules/colorizer.js
modules/injector.js
modules/mouse.js
modules/tester.js
modules/utils.js
modules/xunit.js
modules/casper.js
View file @
a19f297
...
...
@@ -37,7 +37,7 @@ var tester = require('tester');
var
utils
=
require
(
'utils'
);
var
f
=
utils
.
format
;
exports
.
create
=
function
(
options
)
{
exports
.
create
=
function
create
(
options
)
{
return
new
Casper
(
options
);
};
...
...
@@ -46,7 +46,7 @@ exports.create = function(options) {
*
* @param Object options Casper options
*/
var
Casper
=
function
(
options
)
{
var
Casper
=
function
Casper
(
options
)
{
var
DEFAULT_DIE_MESSAGE
=
"Suite explicitely interrupted without any message given."
;
var
DEFAULT_USER_AGENT
=
"Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"
;
// init & checks
...
...
@@ -112,7 +112,7 @@ var Casper = function(options) {
this
.
test
=
tester
.
create
(
this
);
// basic event handlers
this
.
on
(
'deprecated'
,
function
(
message
)
{
this
.
on
(
'deprecated'
,
function
onDeprecated
(
message
)
{
this
.
echo
(
'[deprecated] '
+
message
,
'COMMENT'
);
});
};
...
...
@@ -126,9 +126,9 @@ utils.inherits(Casper, events.EventEmitter);
* @return Casper
*/
Casper
.
prototype
.
back
=
function
back
()
{
return
this
.
then
(
function
()
{
return
this
.
then
(
function
_step
()
{
this
.
emit
(
'back'
);
this
.
evaluate
(
function
()
{
this
.
evaluate
(
function
_evaluate
()
{
history
.
back
();
});
});
...
...
@@ -146,7 +146,7 @@ Casper.prototype.back = function back() {
* @return string Base64 encoded result
*/
Casper
.
prototype
.
base64encode
=
function
base64encode
(
url
,
method
,
data
)
{
return
this
.
evaluate
(
function
(
url
,
method
,
data
)
{
return
this
.
evaluate
(
function
_evaluate
(
url
,
method
,
data
)
{
return
__utils__
.
getBase64
(
url
,
method
,
data
);
},
{
url
:
url
,
method
:
method
,
data
:
data
});
};
...
...
@@ -259,7 +259,7 @@ Casper.prototype.click = function click(selector) {
if
(
!
this
.
exists
(
selector
))
{
throw
new
CasperError
(
"Cannot click on unexistent selector: "
+
selector
);
}
var
clicked
=
this
.
evaluate
(
function
(
selector
)
{
var
clicked
=
this
.
evaluate
(
function
_evaluate
(
selector
)
{
return
__utils__
.
click
(
selector
);
},
{
selector
:
selector
});
if
(
!
clicked
)
{
...
...
@@ -296,7 +296,7 @@ Casper.prototype.createStep = function createStep(fn, options) {
* @return Casper
*/
Casper
.
prototype
.
debugHTML
=
function
debugHTML
()
{
this
.
echo
(
this
.
evaluate
(
function
()
{
this
.
echo
(
this
.
evaluate
(
function
_evaluate
()
{
return
document
.
body
.
innerHTML
;
}));
return
this
;
...
...
@@ -308,7 +308,7 @@ Casper.prototype.debugHTML = function debugHTML() {
* @return Casper
*/
Casper
.
prototype
.
debugPage
=
function
debugPage
()
{
this
.
echo
(
this
.
evaluate
(
function
()
{
this
.
echo
(
this
.
evaluate
(
function
_evaluate
()
{
return
document
.
body
.
innerText
;
}));
return
this
;
...
...
@@ -365,8 +365,8 @@ Casper.prototype.each = function each(array, fn) {
this
.
log
(
"each() only works with arrays"
,
"error"
);
return
this
;
}
(
function
(
self
)
{
array
.
forEach
(
function
(
item
,
i
)
{
(
function
_each
(
self
)
{
array
.
forEach
(
function
_forEach
(
item
,
i
)
{
fn
.
call
(
self
,
self
,
item
,
i
);
});
})(
this
);
...
...
@@ -439,7 +439,7 @@ Casper.prototype.evaluateOrDie = function evaluateOrDie(fn, message) {
* @return Boolean
*/
Casper
.
prototype
.
exists
=
function
exists
(
selector
)
{
return
this
.
evaluate
(
function
(
selector
)
{
return
this
.
evaluate
(
function
_evaluate
(
selector
)
{
return
__utils__
.
exists
(
selector
);
},
{
selector
:
selector
});
};
...
...
@@ -464,7 +464,7 @@ Casper.prototype.exit = function exit(status) {
* @return String
*/
Casper
.
prototype
.
fetchText
=
function
fetchText
(
selector
)
{
return
this
.
evaluate
(
function
(
selector
)
{
return
this
.
evaluate
(
function
_evaluate
(
selector
)
{
return
__utils__
.
fetchText
(
selector
);
},
{
selector
:
selector
});
};
...
...
@@ -485,7 +485,7 @@ Casper.prototype.fill = function fill(selector, vals, submit) {
throw
new
CasperError
(
"Form values must be provided as an object"
);
}
this
.
emit
(
'fill'
,
selector
,
vals
,
submit
);
var
fillResults
=
this
.
evaluate
(
function
(
selector
,
values
)
{
var
fillResults
=
this
.
evaluate
(
function
_evaluate
(
selector
,
values
)
{
return
__utils__
.
fill
(
selector
,
values
);
},
{
selector
:
selector
,
...
...
@@ -494,8 +494,8 @@ Casper.prototype.fill = function fill(selector, vals, submit) {
if
(
!
fillResults
)
{
throw
new
CasperError
(
"Unable to fill form"
);
}
else
if
(
fillResults
.
errors
.
length
>
0
)
{
(
function
(
self
){
fillResults
.
errors
.
forEach
(
function
(
error
)
{
(
function
_each
(
self
){
fillResults
.
errors
.
forEach
(
function
_forEach
(
error
)
{
self
.
log
(
"form error: "
+
error
,
"error"
);
});
})(
this
);
...
...
@@ -506,8 +506,8 @@ Casper.prototype.fill = function fill(selector, vals, submit) {
}
// File uploads
if
(
fillResults
.
files
&&
fillResults
.
files
.
length
>
0
)
{
(
function
(
self
)
{
fillResults
.
files
.
forEach
(
function
(
file
)
{
(
function
_each
(
self
)
{
fillResults
.
files
.
forEach
(
function
_forEach
(
file
)
{
var
fileFieldSelector
=
[
selector
,
'input[name="'
+
file
.
name
+
'"]'
].
join
(
' '
);
self
.
page
.
uploadFile
(
fileFieldSelector
,
file
.
path
);
});
...
...
@@ -515,7 +515,7 @@ Casper.prototype.fill = function fill(selector, vals, submit) {
}
// Form submission?
if
(
submit
)
{
this
.
evaluate
(
function
(
selector
)
{
this
.
evaluate
(
function
_evaluate
(
selector
)
{
var
form
=
__utils__
.
findOne
(
selector
);
var
method
=
(
form
.
getAttribute
(
'method'
)
||
"GET"
).
toUpperCase
();
var
action
=
form
.
getAttribute
(
'action'
)
||
"unknown"
;
...
...
@@ -531,9 +531,9 @@ Casper.prototype.fill = function fill(selector, vals, submit) {
* @return Casper
*/
Casper
.
prototype
.
forward
=
function
forward
(
then
)
{
return
this
.
then
(
function
()
{
return
this
.
then
(
function
_step
()
{
this
.
emit
(
'forward'
);
this
.
evaluate
(
function
()
{
this
.
evaluate
(
function
_evaluate
()
{
history
.
forward
();
});
});
...
...
@@ -545,7 +545,7 @@ Casper.prototype.forward = function forward(then) {
* @return String
*/
Casper
.
prototype
.
getCurrentUrl
=
function
getCurrentUrl
()
{
return
decodeURIComponent
(
this
.
evaluate
(
function
()
{
return
decodeURIComponent
(
this
.
evaluate
(
function
_evaluate
()
{
return
document
.
location
.
href
;
}));
};
...
...
@@ -560,7 +560,7 @@ Casper.prototype.getElementBounds = function getElementBounds(selector) {
if
(
!
this
.
exists
(
selector
))
{
throw
new
CasperError
(
"No element matching selector found: "
+
selector
);
}
var
clipRect
=
this
.
evaluate
(
function
(
selector
)
{
var
clipRect
=
this
.
evaluate
(
function
_evaluate
(
selector
)
{
return
__utils__
.
getElementBounds
(
selector
);
},
{
selector
:
selector
});
if
(
!
utils
.
isClipRect
(
clipRect
))
{
...
...
@@ -576,7 +576,7 @@ Casper.prototype.getElementBounds = function getElementBounds(selector) {
* @return mixed
*/
Casper
.
prototype
.
getGlobal
=
function
getGlobal
(
name
)
{
var
result
=
this
.
evaluate
(
function
(
name
)
{
var
result
=
this
.
evaluate
(
function
_evaluate
(
name
)
{
var
result
=
{};
try
{
result
.
value
=
JSON
.
stringify
(
window
[
name
]);
...
...
@@ -602,7 +602,7 @@ Casper.prototype.getGlobal = function getGlobal(name) {
* @return String
*/
Casper
.
prototype
.
getTitle
=
function
getTitle
()
{
return
this
.
evaluate
(
function
()
{
return
this
.
evaluate
(
function
_evaluate
()
{
return
document
.
title
;
});
};
...
...
@@ -739,12 +739,12 @@ Casper.prototype.resourceExists = function resourceExists(test) {
var
testFn
;
switch
(
utils
.
betterTypeOf
(
test
))
{
case
"string"
:
testFn
=
function
(
res
)
{
testFn
=
function
_test
(
res
)
{
return
res
.
url
.
search
(
test
)
!==
-
1
;
};
break
;
case
"regexp"
:
testFn
=
function
(
res
)
{
testFn
=
function
_test
(
res
)
{
return
test
.
test
(
res
.
url
);
};
break
;
...
...
@@ -788,7 +788,7 @@ Casper.prototype.runStep = function runStep(step) {
this
.
log
(
stepInfo
+
f
(
' %s (HTTP %d)'
,
this
.
getCurrentUrl
(),
this
.
currentHTTPStatus
),
"info"
);
}
if
(
utils
.
isNumber
(
this
.
options
.
stepTimeout
)
&&
this
.
options
.
stepTimeout
>
0
)
{
var
stepTimeoutCheckInterval
=
setInterval
(
function
(
self
,
start
,
stepNum
)
{
var
stepTimeoutCheckInterval
=
setInterval
(
function
_check
(
self
,
start
,
stepNum
)
{
if
(
new
Date
().
getTime
()
-
start
>
self
.
options
.
stepTimeout
)
{
if
(
self
.
step
==
stepNum
)
{
self
.
emit
(
'step.timeout'
);
...
...
@@ -881,7 +881,7 @@ Casper.prototype.start = function start(location, then) {
this
.
emit
(
'started'
);
if
(
utils
.
isNumber
(
this
.
options
.
timeout
)
&&
this
.
options
.
timeout
>
0
)
{
this
.
log
(
f
(
"Execution timeout set to %dms"
,
this
.
options
.
timeout
),
"info"
);
setTimeout
(
function
(
self
)
{
setTimeout
(
function
_check
(
self
)
{
self
.
emit
(
'timeout'
);
if
(
utils
.
isFunction
(
self
.
options
.
onTimeout
))
{
self
.
options
.
onTimeout
.
call
(
self
,
self
);
...
...
@@ -891,7 +891,7 @@ Casper.prototype.start = function start(location, then) {
},
this
.
options
.
timeout
,
this
);
}
if
(
utils
.
isString
(
location
)
&&
location
.
length
>
0
)
{
return
this
.
thenOpen
(
location
,
utils
.
isFunction
(
then
)
?
then
:
this
.
createStep
(
function
(
self
)
{
return
this
.
thenOpen
(
location
,
utils
.
isFunction
(
then
)
?
then
:
this
.
createStep
(
function
_step
(
self
)
{
self
.
log
(
"start page is loaded"
,
"debug"
);
}));
}
...
...
@@ -947,7 +947,7 @@ Casper.prototype.thenClick = function thenClick(selector, then, fallbackToHref)
if
(
arguments
.
length
>
2
)
{
this
.
emit
(
"deprecated"
,
"The thenClick() method does not process the fallbackToHref argument since 0.6"
);
}
this
.
then
(
function
()
{
this
.
then
(
function
_step
()
{
this
.
click
(
selector
);
});
return
utils
.
isFunction
(
then
)
?
this
.
then
(
then
)
:
this
;
...
...
@@ -963,7 +963,7 @@ Casper.prototype.thenClick = function thenClick(selector, then, fallbackToHref)
* @see Casper#evaluate
*/
Casper
.
prototype
.
thenEvaluate
=
function
thenEvaluate
(
fn
,
context
)
{
return
this
.
then
(
function
()
{
return
this
.
then
(
function
_step
()
{
this
.
evaluate
(
fn
,
context
);
});
};
...
...
@@ -977,7 +977,7 @@ Casper.prototype.thenEvaluate = function thenEvaluate(fn, context) {
* @see Casper#open
*/
Casper
.
prototype
.
thenOpen
=
function
thenOpen
(
location
,
then
)
{
this
.
then
(
this
.
createStep
(
function
()
{
this
.
then
(
this
.
createStep
(
function
_step
()
{
this
.
open
(
location
);
},
{
skipLog
:
true
...
...
@@ -1031,7 +1031,7 @@ Casper.prototype.viewport = function viewport(width, height) {
* @return Boolean
*/
Casper
.
prototype
.
visible
=
function
visible
(
selector
)
{
return
this
.
evaluate
(
function
(
selector
)
{
return
this
.
evaluate
(
function
_evaluate
(
selector
)
{
return
__utils__
.
visible
(
selector
);
},
{
selector
:
selector
});
};
...
...
@@ -1052,9 +1052,9 @@ Casper.prototype.wait = function wait(timeout, then) {
if
(
then
&&
!
utils
.
isFunction
(
then
))
{
this
.
die
(
"wait() a step definition must be a function"
);
}
return
this
.
then
(
function
()
{
return
this
.
then
(
function
_step
()
{
this
.
waitStart
();
setTimeout
(
function
(
self
)
{
setTimeout
(
function
_check
(
self
)
{
self
.
log
(
f
(
"wait() finished wating for %dms."
,
timeout
),
"info"
);
if
(
then
)
{
then
.
call
(
self
,
self
);
...
...
@@ -1091,11 +1091,11 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
if
(
then
&&
!
utils
.
isFunction
(
then
))
{
this
.
die
(
"waitFor() next step definition must be a function"
);
}
return
this
.
then
(
function
()
{
return
this
.
then
(
function
_step
()
{
this
.
waitStart
();
var
start
=
new
Date
().
getTime
();
var
condition
=
false
;
var
interval
=
setInterval
(
function
(
self
,
testFx
,
timeout
,
onTimeout
)
{
var
interval
=
setInterval
(
function
_check
(
self
,
testFx
,
timeout
,
onTimeout
)
{
if
((
new
Date
().
getTime
()
-
start
<
timeout
)
&&
!
condition
)
{
condition
=
testFx
.
call
(
self
,
self
);
}
else
{
...
...
@@ -1132,7 +1132,7 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
*/
Casper
.
prototype
.
waitForResource
=
function
waitForResource
(
test
,
then
,
onTimeout
,
timeout
)
{
timeout
=
timeout
?
timeout
:
this
.
defaultWaitTimeout
;
return
this
.
waitFor
(
function
(
self
)
{
return
this
.
waitFor
(
function
_check
(
self
)
{
return
self
.
resourceExists
(
test
);
},
then
,
onTimeout
,
timeout
);
};
...
...
@@ -1149,7 +1149,7 @@ Casper.prototype.waitForResource = function waitForResource(test, then, onTimeou
*/
Casper
.
prototype
.
waitForSelector
=
function
waitForSelector
(
selector
,
then
,
onTimeout
,
timeout
)
{
timeout
=
timeout
?
timeout
:
this
.
defaultWaitTimeout
;
return
this
.
waitFor
(
function
(
self
)
{
return
this
.
waitFor
(
function
_check
(
self
)
{
return
self
.
exists
(
selector
);
},
then
,
onTimeout
,
timeout
);
};
...
...
@@ -1166,7 +1166,7 @@ Casper.prototype.waitForSelector = function waitForSelector(selector, then, onTi
*/
Casper
.
prototype
.
waitWhileSelector
=
function
waitWhileSelector
(
selector
,
then
,
onTimeout
,
timeout
)
{
timeout
=
timeout
?
timeout
:
this
.
defaultWaitTimeout
;
return
this
.
waitFor
(
function
(
self
)
{
return
this
.
waitFor
(
function
_check
(
self
)
{
return
!
self
.
exists
(
selector
);
},
then
,
onTimeout
,
timeout
);
};
...
...
@@ -1183,7 +1183,7 @@ Casper.prototype.waitWhileSelector = function waitWhileSelector(selector, then,
*/
Casper
.
prototype
.
waitUntilVisible
=
function
waitUntilVisible
(
selector
,
then
,
onTimeout
,
timeout
)
{
timeout
=
timeout
?
timeout
:
this
.
defaultWaitTimeout
;
return
this
.
waitFor
(
function
(
self
)
{
return
this
.
waitFor
(
function
_check
(
self
)
{
return
self
.
visible
(
selector
);
},
then
,
onTimeout
,
timeout
);
};
...
...
@@ -1200,7 +1200,7 @@ Casper.prototype.waitUntilVisible = function waitUntilVisible(selector, then, on
*/
Casper
.
prototype
.
waitWhileVisible
=
function
waitWhileVisible
(
selector
,
then
,
onTimeout
,
timeout
)
{
timeout
=
timeout
?
timeout
:
this
.
defaultWaitTimeout
;
return
this
.
waitFor
(
function
(
self
)
{
return
this
.
waitFor
(
function
_check
(
self
)
{
return
!
self
.
visible
(
selector
);
},
then
,
onTimeout
,
timeout
);
};
...
...
@@ -1235,14 +1235,14 @@ function createPage(casper) {
}
else
{
page
=
require
(
'webpage'
).
create
();
}
page
.
onAlert
=
function
(
message
)
{
page
.
onAlert
=
function
onAlert
(
message
)
{
casper
.
log
(
'[alert] '
+
message
,
"info"
,
"remote"
);
casper
.
emit
(
'remote.alert'
,
message
);
if
(
utils
.
isFunction
(
casper
.
options
.
onAlert
))
{
casper
.
options
.
onAlert
.
call
(
casper
,
casper
,
message
);
}
};
page
.
onConsoleMessage
=
function
(
msg
)
{
page
.
onConsoleMessage
=
function
onConsoleMessage
(
msg
)
{
var
level
=
"info"
,
test
=
/^
\[
casper:
(\w
+
)\]\s?(
.*
)
/
.
exec
(
msg
);
if
(
test
&&
test
.
length
===
3
)
{
level
=
test
[
1
];
...
...
@@ -1251,19 +1251,19 @@ function createPage(casper) {
casper
.
log
(
msg
,
level
,
"remote"
);
casper
.
emit
(
'remote.message'
,
msg
);
};
page
.
onInitialized
=
function
()
{
page
.
onInitialized
=
function
onInitialized
()
{
casper
.
emit
(
'page.initialized'
,
this
);
if
(
utils
.
isFunction
(
casper
.
options
.
onPageInitialized
))
{
this
.
log
(
"Post-configuring WebPage instance"
,
"debug"
);
casper
.
options
.
onPageInitialized
.
call
(
casper
,
page
);
}
};
page
.
onLoadStarted
=
function
()
{
page
.
onLoadStarted
=
function
onLoadStarted
()
{
casper
.
loadInProgress
=
true
;
casper
.
resources
=
[];
casper
.
emit
(
'load.started'
);
};
page
.
onLoadFinished
=
function
(
status
)
{
page
.
onLoadFinished
=
function
onLoadFinished
(
status
)
{
if
(
status
!==
"success"
)
{
casper
.
emit
(
'load.failed'
,
{
status
:
status
,
...
...
@@ -1284,7 +1284,7 @@ function createPage(casper) {
if
(
!
utils
.
isArray
(
casper
.
options
.
clientScripts
))
{
throw
new
CasperError
(
"The clientScripts option must be an array"
);
}
else
{
casper
.
options
.
clientScripts
.
forEach
(
function
(
script
)
{
casper
.
options
.
clientScripts
.
forEach
(
function
_forEach
(
script
)
{
if
(
casper
.
page
.
injectJs
(
script
))
{
casper
.
log
(
f
(
'Automatically injected %s client side'
,
script
),
"debug"
);
}
else
{
...
...
@@ -1305,7 +1305,7 @@ function createPage(casper) {
casper
.
emit
(
'load.finished'
,
status
);
casper
.
loadInProgress
=
false
;
};
page
.
onResourceReceived
=
function
(
resource
)
{
page
.
onResourceReceived
=
function
onResourceReceived
(
resource
)
{
casper
.
emit
(
'resource.received'
,
resource
);
if
(
utils
.
isFunction
(
casper
.
options
.
onResourceReceived
))
{
casper
.
options
.
onResourceReceived
.
call
(
casper
,
casper
,
resource
);
...
...
@@ -1325,7 +1325,7 @@ function createPage(casper) {
casper
.
emit
(
'location.changed'
,
resource
.
url
);
}
};
page
.
onResourceRequested
=
function
(
request
)
{
page
.
onResourceRequested
=
function
onResourceRequested
(
request
)
{
casper
.
emit
(
'resource.requested'
,
request
);
if
(
utils
.
isFunction
(
casper
.
options
.
onResourceRequested
))
{
casper
.
options
.
onResourceRequested
.
call
(
casper
,
casper
,
request
);
...
...
modules/cli.js
View file @
a19f297
...
...
@@ -37,24 +37,24 @@ var utils = require('utils');
* @param array phantomArgs phantom.args value
* @return Object
*/
exports
.
parse
=
function
(
phantomArgs
)
{
exports
.
parse
=
function
parse
(
phantomArgs
)
{
var
extract
=
{
args
:
[],
options
:
{},
drop
:
function
(
what
)
{
drop
:
function
drop
(
what
)
{
if
(
utils
.
isNumber
(
what
))
{
// deleting an arg by its position
this
.
args
=
this
.
args
.
filter
(
function
(
arg
,
index
)
{
this
.
args
=
this
.
args
.
filter
(
function
_filter
(
arg
,
index
)
{
return
index
!==
what
;
});
}
else
if
(
utils
.
isString
(
what
))
{
// deleting an arg by its value
this
.
args
=
this
.
args
.
filter
(
function
(
arg
)
{
this
.
args
=
this
.
args
.
filter
(
function
_filter
(
arg
)
{
return
arg
!==
what
;
});
// deleting an option by its name (key)
var
self
=
this
;
Object
.
keys
(
this
.
options
).
forEach
(
function
(
option
)
{
Object
.
keys
(
this
.
options
).
forEach
(
function
_forEach
(
option
)
{
if
(
option
===
what
)
{
delete
self
.
options
[
what
];
}
...
...
@@ -63,7 +63,7 @@ exports.parse = function(phantomArgs) {
throw
new
CasperError
(
"cannot drop argument of type "
+
typeof
what
);
}
},
has
:
function
(
what
)
{
has
:
function
has
(
what
)
{
if
(
utils
.
isNumber
(
what
))
{
return
what
in
this
.
args
;
}
else
if
(
utils
.
isString
(
what
))
{
...
...
@@ -72,7 +72,7 @@ exports.parse = function(phantomArgs) {
throw
new
CasperError
(
"Unsupported cli arg tester "
+
typeof
what
);
}
},
get
:
function
(
what
)
{
get
:
function
get
(
what
)
{
if
(
utils
.
isNumber
(
what
))
{
return
this
.
args
[
what
];
}
else
if
(
utils
.
isString
(
what
))
{
...
...
@@ -82,7 +82,7 @@ exports.parse = function(phantomArgs) {
}
}
};
phantomArgs
.
forEach
(
function
(
arg
)
{
phantomArgs
.
forEach
(
function
_forEach
(
arg
)
{
if
(
arg
.
indexOf
(
'--'
)
===
0
)
{
// named option
var
optionMatch
=
arg
.
match
(
/^--
(
.*
)
=
(
.*
)
/i
);
...
...
modules/clientutils.js
View file @
a19f297
...
...
@@ -28,14 +28,14 @@
*
*/
(
function
(
exports
)
{
exports
.
create
=
function
()
{
exports
.
create
=
function
create
()
{
return
new
ClientUtils
();
};
/**
* Casper client-side helpers.
*/
ClientUtils
=
function
()
{
ClientUtils
=
function
ClientUtils
()
{
var
BASE64_ENCODE_CHARS
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
var
BASE64_DECODE_CHARS
=
new
Array
(
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
...
...
@@ -54,7 +54,7 @@
* @param String selector A CSS3 selector to the element to click
* @return Boolean
*/
this
.
click
=
function
(
selector
)
{
this
.
click
=
function
click
(
selector
)
{
var
elem
=
this
.
findOne
(
selector
);
if
(
!
elem
)
{
this
.
log
(
"click(): Couldn't find any element matching '"
+
selector
+
"' selector"
,
"error"
);
...
...
@@ -73,7 +73,7 @@
* @param String str The base64 encoded contents
* @return string
*/
this
.
decode
=
function
(
str
)
{
this
.
decode
=
function
decode
(
str
)
{
var
c1
,
c2
,
c3
,
c4
,
i
=
0
,
len
=
str
.
length
,
out
=
""
;
while
(
i
<
len
)
{
do
{
...
...
@@ -121,7 +121,7 @@
* @param String str The string content to encode
* @return string
*/
this
.
encode
=
function
(
str
)
{
this
.
encode
=
function
encode
(
str
)
{
var
out
=
""
,
i
=
0
,
len
=
str
.
length
,
c1
,
c2
,
c3
;
while
(
i
<
len
)
{
c1
=
str
.
charCodeAt
(
i
++
)
&
0xff
;
...
...
@@ -154,7 +154,7 @@
* @param String selector CSS3 selector
* @return Boolean
*/
this
.
exists
=
function
(
selector
)
{
this
.
exists
=
function
exists
(
selector
)
{
try
{
return
document
.
querySelectorAll
(
selector
).
length
>
0
;
}
catch
(
e
)
{
...
...
@@ -169,10 +169,10 @@
* @param String selector A CSS3 selector
* @return String
*/
this
.
fetchText
=
function
(
selector
)
{
this
.
fetchText
=
function
fetchText
(
selector
)
{
var
text
=
''
,
elements
=
this
.
findAll
(
selector
);
if
(
elements
&&
elements
.
length
)
{
Array
.
prototype
.
forEach
.
call
(
elements
,
function
(
element
)
{
Array
.
prototype
.
forEach
.
call
(
elements
,
function
_forEach
(
element
)
{
text
+=
element
.
innerText
;
});
}
...
...
@@ -186,7 +186,7 @@
* @param Object vals Field values
* @return Object An object containing setting result for each field, including file uploads
*/
this
.
fill
=
function
(
form
,
vals
)
{
this
.
fill
=
function
fill
(
form
,
vals
)
{
var
out
=
{
errors
:
[],
fields
:
[],
...
...
@@ -240,7 +240,7 @@
* @param String selector CSS3 selector
* @return NodeList|undefined
*/
this
.
findAll
=
function
(
selector
)
{
this
.
findAll
=
function
findAll
(
selector
)
{
try
{
return
document
.
querySelectorAll
(
selector
);
}
catch
(
e
)
{
...
...
@@ -254,7 +254,7 @@
* @param String selector CSS3 selector
* @return HTMLElement|undefined
*/
this
.
findOne
=
function
(
selector
)
{
this
.
findOne
=
function
findOne
(
selector
)
{
try
{
return
document
.
querySelector
(
selector
);
}
catch
(
e
)
{
...
...
@@ -271,7 +271,7 @@
* @param Object data The request data, optional
* @return String Base64 contents string
*/
this
.
getBase64
=
function
(
url
,
method
,
data
)
{
this
.
getBase64
=
function
getBase64
(
url
,
method
,
data
)
{
return
this
.
encode
(
this
.
getBinary
(
url
,
method
,
data
));
};
...
...
@@ -284,7 +284,7 @@
* @param Object data
* @return string
*/
this
.
getBinary
=
function
(
url
,
method
,
data
)
{
this
.
getBinary
=
function
getBinary
(
url
,
method
,
data
)
{
try
{
var
xhr
=
new
XMLHttpRequest
(),
dataString
=
""
;
if
(
typeof
method
!==
"string"
||
[
"GET"
,
"POST"
].
indexOf
(
method
.
toUpperCase
())
===
-
1
)
{
...
...
@@ -326,7 +326,7 @@
* @param String selector
* @return Object or null
*/
this
.
getElementBounds
=
function
(
selector
)
{
this
.
getElementBounds
=
function
getElementBounds
(
selector
)
{
try
{
var
clipRect
=
document
.
querySelector
(
selector
).
getBoundingClientRect
();
return
{
...
...
@@ -347,7 +347,7 @@
* @param String message The message to log
* @param String level The log level
*/
this
.
log
=
function
(
message
,
level
)
{
this
.
log
=
function
log
(
message
,
level
)
{
console
.
log
(
"[casper:"
+
(
level
||
"debug"
)
+
"] "
+
message
);
};
...
...
@@ -358,7 +358,7 @@
* @param HTMLElement|NodeList field One or more element defining a field
* @param mixed value The field value to set
*/
this
.
setField
=
function
(
field
,
value
)
{
this
.
setField
=
function
setField
(
field
,
value
)
{
var
fields
,
out
;
value
=
value
||
""
;
if
(
field
instanceof
NodeList
)
{
...
...
@@ -403,7 +403,7 @@
if
(
!
Array
.
isArray
(
values
))
{
values
=
[
values
];
}
Array
.
prototype
.
forEach
.
call
(
fields
,
function
(
f
)
{
Array
.
prototype
.
forEach
.
call
(
fields
,
function
_forEach
(
f
)
{
f
.
checked
=
values
.
indexOf
(
f
.
value
)
!==
-
1
?
true
:
false
;
});
}
else
{
...
...
@@ -418,7 +418,7 @@
};
case
"radio"
:
if
(
fields
)
{
Array
.
prototype
.
forEach
.
call
(
fields
,
function
(
e
)
{
Array
.
prototype
.
forEach
.
call
(
fields
,
function
_forEach
(
e
)
{
e
.
checked
=
(
e
.
value
===
value
);
});
}
else
{
...
...
@@ -452,7 +452,7 @@
* @param String selector CSS3 selector
* @return Boolean
*/
this
.
visible
=
function
(
selector
)
{
this
.
visible
=
function
visible
(
selector
)
{
try
{
var
el
=
document
.
querySelector
(
selector
);
return
el
&&
el
.
style
.
visibility
!==
'hidden'
&&
el
.
offsetHeight
>
0
&&
el
.
offsetWidth
>
0
;
...
...
modules/colorizer.js
View file @
a19f297
...
...
@@ -41,7 +41,7 @@ exports.create = function create() {
*
* (c) Fabien Potencier, Symfony project, MIT license
*/
var
Colorizer
=
function
()
{
var
Colorizer
=
function
Colorizer
()
{
var
options
=
{
bold
:
1
,
underscore
:
4
,
blink
:
5
,
reverse
:
7
,
conceal
:
8
};
var
foreground
=
{
black
:
30
,
red
:
31
,
green
:
32
,
yellow
:
33
,
blue
:
34
,
magenta
:
35
,
cyan
:
36
,
white
:
37
};
var
background
=
{
black
:
40
,
red
:
41
,
green
:
42
,
yellow
:
43
,
blue
:
44
,
magenta
:
45
,
cyan
:
46
,
white
:
47
};
...
...
modules/injector.js
View file @
a19f297
...
...
@@ -30,7 +30,7 @@
var
utils
=
require
(
'utils'
);
exports
.
create
=
function
(
fn
)
{
exports
.
create
=
function
create
(
fn
)
{
return
new
FunctionArgsInjector
(
fn
);
};
...
...
@@ -39,18 +39,18 @@ exports.create = function(fn) {
*
* FIXME: use new Function() instead of eval()
*/
var
FunctionArgsInjector
=
function
(
fn
)
{
var
FunctionArgsInjector
=
function
FunctionArgsInjector
(
fn
)
{
if
(
!
utils
.
isFunction
(
fn
))
{
throw
new
CasperError
(
"FunctionArgsInjector() can only process functions"
);
}
this
.
fn
=
fn
;
this
.
extract
=
function
(
fn
)
{
this
.
extract
=
function
extract
(
fn
)
{
var
match
=
/^function
\s?(\w
+
)?\s?\((
.*
)\)\s?\{([\s\S]
*
)\}
/i
.
exec
(
fn
.
toString
().
trim
());
if
(
match
&&
match
.
length
>
1
)
{
var
args
=
match
[
2
].
split
(
','
).
map
(
function
(
arg
)
{
var
args
=
match
[
2
].
split
(
','
).
map
(
function
_map
(
arg
)
{
return
arg
.
replace
(
new
RegExp
(
/
\/\*
+.*
\*\/
/ig
),
""
).
trim
();
}).
filter
(
function
(
arg
)
{
}).
filter
(
function
_filter
(
arg
)
{
return
arg
;
})
||
[];
return
{
...
...
@@ -61,7 +61,7 @@ var FunctionArgsInjector = function(fn) {
}
};
this
.
process
=
function
(
values
)
{
this
.
process
=
function
process
(
values
)
{
var
fnObj
=
this
.
extract
(
this
.
fn
);
if
(
!
utils
.
isObject
(
fnObj
))
{
throw
new
CasperError
(
"Unable to process function "
+
this
.
fn
.
toString
());
...
...
@@ -70,13 +70,13 @@ var FunctionArgsInjector = function(fn) {
return
'function '
+
(
fnObj
.
name
||
''
)
+
'(){'
+
inject
+
fnObj
.
body
+
'}'
;
};
this
.
getArgsInjectionString
=
function
(
args
,
values
)
{
this
.
getArgsInjectionString
=
function
getArgsInjectionString
(
args
,
values
)
{
values
=
typeof
values
===
"object"
?
values
:
{};
var
jsonValues
=
escape
(
encodeURIComponent
(
JSON
.
stringify
(
values
)));
var
inject
=
[
'var __casper_params__ = JSON.parse(decodeURIComponent(unescape(\''
+
jsonValues
+
'\')));'
];
args
.
forEach
(
function
(
arg
)
{
args
.
forEach
(
function
_forEach
(
arg
)
{
if
(
arg
in
values
)
{
inject
.
push
(
'var '
+
arg
+
'=__casper_params__["'
+
arg
+
'"];'
);
}
...
...
modules/mouse.js
View file @
a19f297
...
...
@@ -30,11 +30,11 @@
var
utils
=
require
(
'utils'
);
exports
.
create
=
function
(
casper
)
{
exports
.
create
=
function
create
(
casper
)
{
return
new
Mouse
(
casper
);
};
var
Mouse
=
function
(
casper
)
{
var
Mouse
=
function
Mouse
(
casper
)
{
if
(
!
utils
.
isCasperObject
(
casper
))
{
throw
new
CasperError
(
'Mouse() needs a Casper instance'
);
}
...
...
modules/tester.js
View file @
a19f297
...
...
@@ -33,7 +33,7 @@ var events = require('events');
var
utils
=
require
(
'utils'
);
var
f
=
utils
.
format
;
exports
.
create
=
function
(
casper
,
options
)
{
exports
.
create
=
function
create
(
casper
,
options
)
{
return
new
Tester
(
casper
,
options
);
};
...
...
@@ -41,7 +41,7 @@ exports.create = function(casper, options) {
* Casper tester: makes assertions, stores test results and display then.
*
*/
var
Tester
=
function
(
casper
,
options
)
{
var
Tester
=
function
Tester
(
casper
,
options
)
{
if
(
!
utils
.
isCasperObject
(
casper
))
{
throw
new
CasperError
(
"Tester needs a Casper instance"
);
}
...
...
@@ -64,16 +64,16 @@ var Tester = function(casper, options) {
};
// events
casper
.
on
(
'step.error'
,
function
(
e
)
{
casper
.
on
(
'step.error'
,
function
onStepError
(
e
)
{
casper
.
test
.
fail
(
e
);
casper
.
test
.
done
();
});
this
.
on
(
'success'
,
function
(
success
)
{
this
.
on
(
'success'
,
function
onSuccess
(
success
)
{
this
.
exporter
.
addSuccess
(
fs
.
absolute
(
success
.
file
),
success
.
message
);
});
this
.
on
(
'fail'
,
function
(
failure
)
{
this
.
on
(
'fail'
,
function
onFail
(
failure
)
{
this
.
exporter
.
addFailure
(
fs
.
absolute
(
failure
.
file
),
failure
.
message
,
failure
.
details
||
"test failed"
,
failure
.
type
||
"unknown"
);
this
.
testResults
.
failures
.
push
(
failure
);
});
...
...
@@ -274,7 +274,7 @@ var Tester = function(casper, options) {
* @param String message Test description
*/
this
.
assertTextExists
=
function
assertTextExists
(
text
,
message
)
{
return
this
.
assert
((
casper
.
evaluate
(
function
()
{
return
this
.
assert
((
casper
.
evaluate
(
function
_evaluate
()
{
return
document
.
body
.
innerText
;
}).
indexOf
(
text
)
!=
-
1
),
message
);
};
...
...
@@ -367,7 +367,7 @@ var Tester = function(casper, options) {
new
Function
(
'casper'
,
phantom
.
getScriptCode
(
file
))(
casper
);
}
catch
(
e
)
{
var
self
=
this
;
phantom
.
processScriptError
(
e
,
file
,
function
(
error
)
{
phantom
.
processScriptError
(
e
,
file
,
function
onTestScriptError
(
error
)
{
// do not abort the whole suite, just fail fast displaying the
// caught error and process next suite
self
.
fail
(
e
);
...
...
@@ -395,17 +395,17 @@ var Tester = function(casper, options) {
if
(
!
fs
.
isDirectory
(
dir
))
{
return
[];
}
var
entries
=
fs
.
list
(
dir
).
filter
(
function
(
entry
)
{
var
entries
=
fs
.
list
(
dir
).
filter
(
function
_filter
(
entry
)
{
return
entry
!==
'.'
&&
entry
!==
'..'
;
}).
map
(
function
(
entry
)
{
}).
map
(
function
_map
(
entry
)
{
return
fs
.
absolute
(
fs
.
pathJoin
(
dir
,
entry
));
});
entries
.
forEach
(
function
(
entry
)
{
entries
.
forEach
(
function
_forEach
(
entry
)
{
if
(
fs
.
isDirectory
(
entry
))
{
entries
=
entries
.
concat
(
self
.
findTestFiles
(
entry
));
}
});
return
entries
.
filter
(
function
(
entry
)
{
return
entries
.
filter
(
function
_filter
(
entry
)
{
return
utils
.
isJsFile
(
fs
.
absolute
(
fs
.
pathJoin
(
dir
,
entry
)));
}).
sort
();
};
...
...
@@ -452,7 +452,7 @@ var Tester = function(casper, options) {
return
;
}
casper
.
echo
(
f
(
"\nDetails for the %d failed test%s:\n"
,
failures
.
length
,
failures
.
length
>
1
?
"s"
:
""
),
"PARAMETER"
);
failures
.
forEach
(
function
(
failure
)
{
failures
.
forEach
(
function
_forEach
(
failure
)
{
var
message
,
line
;
if
(
utils
.
isType
(
failure
.
message
,
"object"
)
&&
failure
.
message
.
stack
)
{
line
=
failure
.
message
.
line
?
failure
.
message
.
line
:
0
;
...
...
@@ -516,7 +516,7 @@ var Tester = function(casper, options) {
if
(
arguments
.
length
===
0
)
{
throw
new
CasperError
(
"runSuites() needs at least one path argument"
);
}
Array
.
prototype
.
forEach
.
call
(
arguments
,
function
(
path
)
{
Array
.
prototype
.
forEach
.
call
(
arguments
,
function
_forEach
(
path
)
{
if
(
!
fs
.
exists
(
path
))
{
self
.
bar
(
f
(
"Path %s doesn't exist"
,
path
),
"RED_BAR"
);
}
...
...
@@ -531,7 +531,7 @@ var Tester = function(casper, options) {
casper
.
exit
(
1
);
}
var
current
=
0
;
var
interval
=
setInterval
(
function
(
self
)
{
var
interval
=
setInterval
(
function
_check
(
self
)
{
if
(
self
.
running
)
{
return
;
}
...
...
modules/utils.js
View file @
a19f297
...
...
@@ -104,7 +104,7 @@ function format(f) {
i
=
1
;
var
args
=
arguments
;
var
len
=
args
.
length
;
var
str
=
String
(
f
).
replace
(
/%
[
sdj%
]
/g
,
function
(
x
)
{
var
str
=
String
(
f
).
replace
(
/%
[
sdj%
]
/g
,
function
_replace
(
x
)
{
if
(
i
>=
len
)
return
x
;
switch
(
x
)
{
case
'%s'
:
...
...
@@ -352,7 +352,7 @@ exports.node = node;
*/
function
serialize
(
value
)
{
if
(
isArray
(
value
))
{
value
=
value
.
map
(
function
(
prop
)
{
value
=
value
.
map
(
function
_map
(
prop
)
{
return
isFunction
(
prop
)
?
prop
.
toString
().
replace
(
/
\s{2,}
/
,
''
)
:
prop
;
});
}
...
...
modules/xunit.js
View file @
a19f297
...
...
@@ -31,7 +31,7 @@
var
utils
=
require
(
'utils'
);
var
fs
=
require
(
'fs'
);
exports
.
create
=
function
()
{
exports
.
create
=
function
create
()
{
return
new
XUnitExporter
();
};
...
...
@@ -39,9 +39,9 @@ exports.create = function() {
* JUnit XML (xUnit) exporter for test results.
*
*/
XUnitExporter
=
function
()
{
XUnitExporter
=
function
XUnitExporter
()
{
this
.
_xml
=
utils
.
node
(
'testsuite'
);
this
.
_xml
.
toString
=
function
()
{
this
.
_xml
.
toString
=
function
toString
()
{
return
this
.
outerHTML
;
// ouch
};
};
...
...
@@ -53,7 +53,7 @@ exports.XUnitExporter = XUnitExporter;
* @param String classname
* @param String name
*/
XUnitExporter
.
prototype
.
addSuccess
=
function
(
classname
,
name
)
{
XUnitExporter
.
prototype
.
addSuccess
=
function
addSuccess
(
classname
,
name
)
{
this
.
_xml
.
appendChild
(
utils
.
node
(
'testcase'
,
{
classname
:
generateClassName
(
classname
),
name
:
name
...
...
@@ -68,7 +68,7 @@ XUnitExporter.prototype.addSuccess = function(classname, name) {
* @param String message
* @param String type
*/
XUnitExporter
.
prototype
.
addFailure
=
function
(
classname
,
name
,
message
,
type
)
{
XUnitExporter
.
prototype
.
addFailure
=
function
addFailure
(
classname
,
name
,
message
,
type
)
{
var
fnode
=
utils
.
node
(
'testcase'
,
{
classname
:
generateClassName
(
classname
),
name
:
name
...
...
@@ -110,6 +110,6 @@ function generateClassName(classname) {
*
* @return HTMLElement
*/
XUnitExporter
.
prototype
.
getXML
=
function
()
{
XUnitExporter
.
prototype
.
getXML
=
function
getXML
()
{
return
this
.
_xml
;
};
...
...
Please
register
or
sign in
to post a comment