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
89a3092c
...
89a3092c465ae136beafa6d21a41f93e785294df
authored
2012-01-03 19:25:22 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added format() helper; removed 'casper.' suffix in event names
1 parent
18b1423a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
142 additions
and
48 deletions
LICENSE
bin/bootstrap.js
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
samples/events.coffee
LICENSE
View file @
89a3092
Copyright (c) 2011 Nicolas Perriault
Copyright (c) 2011
-2012
Nicolas Perriault
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
...
...
bin/bootstrap.js
View file @
89a3092
...
...
@@ -4,7 +4,9 @@
* Documentation: http://n1k0.github.com/casperjs/
* Repository: http://github.com/n1k0/casperjs
*
* Copyright (c) 2011 Nicolas Perriault
* Copyright (c) 2011-2012 Nicolas Perriault
*
* Part of source code is Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
...
...
@@ -25,6 +27,7 @@
* DEALINGS IN THE SOFTWARE.
*
*/
if
(
!
phantom
.
casperLoaded
)
{
// see http://semver.org/
phantom
.
casperVersion
=
{
...
...
@@ -149,6 +152,7 @@ if (!phantom.casperLoaded) {
paths
.
push
(
fs
.
pathJoin
(
dir
,
'node_modules'
,
path
));
dir
=
fs
.
dirname
(
dir
);
}
paths
.
push
(
fs
.
pathJoin
(
requireDir
,
'lib'
,
path
));
paths
.
push
(
fs
.
pathJoin
(
requireDir
,
'modules'
,
path
));
}
paths
.
forEach
(
function
(
testPath
)
{
...
...
@@ -221,7 +225,9 @@ if (!!phantom.casperArgs.options.version) {
console
.
log
(
phantom
.
casperVersion
.
toString
());
phantom
.
exit
(
0
);
}
else
if
(
phantom
.
casperArgs
.
args
.
length
===
0
||
!!
phantom
.
casperArgs
.
options
.
help
)
{
var
phantomVersion
=
[
phantom
.
version
.
major
,
phantom
.
version
.
minor
,
phantom
.
version
.
patch
].
join
(
'.'
);
console
.
log
(
'CasperJS version '
+
phantom
.
casperVersion
.
toString
()
+
' at '
+
phantom
.
casperPath
);
console
.
log
(
'Using PhantomJS version '
+
phantomVersion
);
console
.
log
(
'Usage: casperjs script.(js|coffee) [options...]'
);
console
.
log
(
'Read the docs http://n1k0.github.com/casperjs/'
);
phantom
.
exit
(
0
);
...
...
modules/casper.js
View file @
89a3092
This diff is collapsed.
Click to expand it.
modules/cli.js
View file @
89a3092
...
...
@@ -4,7 +4,9 @@
* Documentation: http://n1k0.github.com/casperjs/
* Repository: http://github.com/n1k0/casperjs
*
* Copyright (c) 2011 Nicolas Perriault
* Copyright (c) 2011-2012 Nicolas Perriault
*
* Part of source code is Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
...
...
modules/clientutils.js
View file @
89a3092
...
...
@@ -4,7 +4,9 @@
* Documentation: http://n1k0.github.com/casperjs/
* Repository: http://github.com/n1k0/casperjs
*
* Copyright (c) 2011 Nicolas Perriault
* Copyright (c) 2011-2012 Nicolas Perriault
*
* Part of source code is Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
...
...
modules/colorizer.js
View file @
89a3092
...
...
@@ -4,7 +4,9 @@
* Documentation: http://n1k0.github.com/casperjs/
* Repository: http://github.com/n1k0/casperjs
*
* Copyright (c) 2011 Nicolas Perriault
* Copyright (c) 2011-2012 Nicolas Perriault
*
* Part of source code is Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
...
...
modules/injector.js
View file @
89a3092
...
...
@@ -4,7 +4,9 @@
* Documentation: http://n1k0.github.com/casperjs/
* Repository: http://github.com/n1k0/casperjs
*
* Copyright (c) 2011 Nicolas Perriault
* Copyright (c) 2011-2012 Nicolas Perriault
*
* Part of source code is Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
...
...
modules/mouse.js
View file @
89a3092
/*!
* Casper is a navigation utility for PhantomJS.
*
* Documentation: http://n1k0.github.com/casperjs/
* Repository: http://github.com/n1k0/casperjs
*
* Copyright (c) 2011-2012 Nicolas Perriault
*
* Part of source code is Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
var
utils
=
require
(
'utils'
);
exports
.
create
=
function
(
casper
)
{
...
...
@@ -35,14 +65,14 @@ var Mouse = function(casper) {
if
(
!
utils
.
isString
(
selector
))
{
throw
new
Error
(
'No valid CSS selector passed: '
+
selector
);
}
casper
.
page
.
sendEvent
.
apply
(
casper
.
page
,
[
type
].
concat
(
computeCenter
(
selector
)))
casper
.
page
.
sendEvent
.
apply
(
casper
.
page
,
[
type
].
concat
(
computeCenter
(
selector
)))
;
break
;
case
2
:
// coordinates
if
(
!
utils
.
isNumber
(
args
[
1
])
||
!
utils
.
isNumber
(
args
[
2
]))
{
throw
new
Error
(
'No valid coordinates passed'
);
}
casper
.
page
.
sendEvent
(
type
,
args
[
0
],
args
[
1
])
casper
.
page
.
sendEvent
(
type
,
args
[
0
],
args
[
1
])
;
break
;
default
:
throw
new
Error
(
'Too many arguments'
);
...
...
@@ -51,18 +81,18 @@ var Mouse = function(casper) {
this
.
click
=
function
()
{
processEvent
(
'click'
,
arguments
);
}
,
}
;
this
.
down
=
function
()
{
processEvent
(
'mousedown'
,
arguments
);
}
,
}
;
this
.
move
=
function
()
{
processEvent
(
'mousemove'
,
arguments
);
}
,
}
;
this
.
up
=
function
()
{
processEvent
(
'mouseup'
,
arguments
);
}
}
;
};
exports
.
Mouse
=
Mouse
;
...
...
modules/tester.js
View file @
89a3092
...
...
@@ -4,7 +4,9 @@
* Documentation: http://n1k0.github.com/casperjs/
* Repository: http://github.com/n1k0/casperjs
*
* Copyright (c) 2011 Nicolas Perriault
* Copyright (c) 2011-2012 Nicolas Perriault
*
* Part of source code is Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
...
...
modules/utils.js
View file @
89a3092
...
...
@@ -4,7 +4,9 @@
* Documentation: http://n1k0.github.com/casperjs/
* Repository: http://github.com/n1k0/casperjs
*
* Copyright (c) 2011 Nicolas Perriault
* Copyright (c) 2011-2012 Nicolas Perriault
*
* Part of source code is Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
...
...
@@ -86,6 +88,75 @@ function fillBlanks(text, pad) {
exports
.
fillBlanks
=
fillBlanks
;
/**
* Formats a string with passed parameters. Ported from nodejs `util.format()`.
*
* @return String
*/
function
format
(
f
)
{
var
i
;
if
(
typeof
f
!==
'string'
)
{
var
objects
=
[];
for
(
i
=
0
;
i
<
arguments
.
length
;
i
++
)
{
objects
.
push
(
inspect
(
arguments
[
i
]));
}
return
objects
.
join
(
' '
);
}
i
=
1
;
var
args
=
arguments
;
var
len
=
args
.
length
;
var
str
=
String
(
f
).
replace
(
/%
[
sdj%
]
/g
,
function
(
x
)
{
if
(
i
>=
len
)
return
x
;
switch
(
x
)
{
case
'%s'
:
return
String
(
args
[
i
++
]);
case
'%d'
:
return
Number
(
args
[
i
++
]);
case
'%j'
:
return
JSON
.
stringify
(
args
[
i
++
]);
case
'%%'
:
return
'%'
;
default
:
return
x
;
}
});
for
(
var
x
=
args
[
i
];
i
<
len
;
x
=
args
[
++
i
])
{
if
(
x
===
null
||
typeof
x
!==
'object'
)
{
str
+=
' '
+
x
;
}
else
{
str
+=
' '
+
inspect
(
x
);
}
}
return
str
;
}
exports
.
format
=
format
;
/**
* Inherit the prototype methods from one constructor into another.
*
* The Function.prototype.inherits from lang.js rewritten as a standalone
* function (not on Function.prototype). NOTE: If this file is to be loaded
* during bootstrapping this function needs to be revritten using some native
* functions as prototype setup using normal JavaScript does not work as
* expected during bootstrapping (see mirror.js in r114903).
*
* @param {function} ctor Constructor function which needs to inherit the
* prototype.
* @param {function} superCtor Constructor function to inherit prototype from.
*/
function
inherits
(
ctor
,
superCtor
)
{
ctor
.
super_
=
superCtor
;
ctor
.
prototype
=
Object
.
create
(
superCtor
.
prototype
,
{
constructor
:
{
value
:
ctor
,
enumerable
:
false
,
writable
:
true
,
configurable
:
true
}
});
}
exports
.
inherits
=
inherits
;
/**
* Checks if value is a javascript Array
*
* @param mixed value
...
...
@@ -243,14 +314,14 @@ exports.mergeObjects = mergeObjects;
* @return HTMLElement
*/
function
node
(
name
,
attributes
)
{
var
node
=
document
.
createElement
(
name
);
var
_
node
=
document
.
createElement
(
name
);
for
(
var
attrName
in
attributes
)
{
var
value
=
attributes
[
attrName
];
if
(
attributes
.
hasOwnProperty
(
attrName
)
&&
isString
(
attrName
))
{
node
.
setAttribute
(
attrName
,
value
);
_
node
.
setAttribute
(
attrName
,
value
);
}
}
return
node
;
return
_
node
;
}
exports
.
node
=
node
;
...
...
@@ -269,28 +340,3 @@ function serialize(value) {
return
JSON
.
stringify
(
value
,
null
,
4
);
}
exports
.
serialize
=
serialize
;
/**
* Inherit the prototype methods from one constructor into another.
*
* The Function.prototype.inherits from lang.js rewritten as a standalone
* function (not on Function.prototype). NOTE: If this file is to be loaded
* during bootstrapping this function needs to be revritten using some native
* functions as prototype setup using normal JavaScript does not work as
* expected during bootstrapping (see mirror.js in r114903).
*
* @param {function} ctor Constructor function which needs to inherit the
* prototype.
* @param {function} superCtor Constructor function to inherit prototype from.
*/
exports
.
inherits
=
function
(
ctor
,
superCtor
)
{
ctor
.
super_
=
superCtor
;
ctor
.
prototype
=
Object
.
create
(
superCtor
.
prototype
,
{
constructor
:
{
value
:
ctor
,
enumerable
:
false
,
writable
:
true
,
configurable
:
true
}
});
};
...
...
modules/xunit.js
View file @
89a3092
...
...
@@ -4,7 +4,9 @@
* Documentation: http://n1k0.github.com/casperjs/
* Repository: http://github.com/n1k0/casperjs
*
* Copyright (c) 2011 Nicolas Perriault
* Copyright (c) 2011-2012 Nicolas Perriault
*
* Part of source code is Copyright Joyent, Inc. and other Node contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
...
...
samples/events.coffee
View file @
89a3092
casper
=
require
(
'casper'
).
create
()
casper
.
on
"
casper.
http.status.200"
,
(
resource
)
->
casper
.
on
"http.status.200"
,
(
resource
)
->
casper
.
echo
"
#{
resource
.
url
}
is OK"
,
"INFO"
casper
.
on
"
casper.
http.status.301"
,
(
resource
)
->
casper
.
on
"http.status.301"
,
(
resource
)
->
casper
.
echo
"
#{
resource
.
url
}
is permanently redirected"
,
"PARAMETER"
casper
.
on
"
casper.
http.status.302"
,
(
resource
)
->
casper
.
on
"http.status.302"
,
(
resource
)
->
casper
.
echo
"
#{
resource
.
url
}
is temporarily redirected"
,
"PARAMETER"
casper
.
on
"
casper.
http.status.404"
,
(
resource
)
->
casper
.
on
"http.status.404"
,
(
resource
)
->
casper
.
echo
"
#{
resource
.
url
}
is not found"
,
"COMMENT"
casper
.
on
"
casper.
http.status.500"
,
(
resource
)
->
casper
.
on
"http.status.500"
,
(
resource
)
->
casper
.
echo
"
#{
resource
.
url
}
is in error"
,
"ERROR"
links
=
[
...
...
Please
register
or
sign in
to post a comment