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
4e7d7382
...
4e7d7382e488c3c34f7350fb6a112e1ab5b67f39
authored
2011-12-15 14:46:15 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refs #28 - fixed several issues with portability
1 parent
6bfdb427
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
44 deletions
casper.js
lib/casper.js
lib/cli.js
lib/tester.js
tests/run.js
tests/suites/casper/encode.js
casper.js
View file @
4e7d738
...
...
@@ -25,43 +25,39 @@
* DEALINGS IN THE SOFTWARE.
*
*/
var
fs
=
require
(
'fs'
);
(
function
(
phantom
)
{
var
fs
=
require
(
'fs'
);
var
casperScript
=
phantom
.
args
[
1
];
fs
.
pathJoin
=
function
()
{
return
Array
.
prototype
.
join
.
call
(
arguments
,
this
.
separator
);
};
if
(
phantom
.
args
.
length
<
2
)
{
if
(
!
fs
.
isDirectory
(
phantom
.
args
[
0
]))
{
console
.
log
(
'First argument must be the path to casper root path'
);
if
(
!
fs
.
isDirectory
(
phantom
.
args
[
0
])
||
!
fs
.
isFile
(
fs
.
pathJoin
(
phantom
.
args
[
0
],
'casper.js'
))
)
{
console
.
log
(
'First argument must be the absolute path to casper root path.'
);
phantom
.
exit
(
1
);
}
if
(
!
fs
.
isFile
(
casperScript
))
{
console
.
log
(
'Usage: $ casperjs script.js'
);
}
phantom
.
exit
(
1
);
}
var
casperPath
=
phantom
.
args
[
0
];
function
pathJoin
()
{
return
Array
.
prototype
.
join
.
call
(
arguments
,
fs
.
separator
);
}
var
casperLibPath
=
pathJoin
(
casperPath
,
'lib'
);
if
(
!
fs
.
isDirectory
(
casperLibPath
))
{
console
.
log
(
"Couldn't find CasperJS lib directory: "
+
casperLibPath
);
phantom
.
exit
(
1
);
}
[
'casper.js'
,
'clientutils.js'
,
'colorizer.js'
,
'injector.js'
,
'tester.js'
,
'utils.js'
,
'xunit.js'
].
forEach
(
function
(
lib
)
{
phantom
.
injectJs
(
pathJoin
(
casperLibPath
,
lib
));
});
if
(
!
fs
.
isFile
(
phantom
.
args
[
1
]))
{
console
.
log
(
'Usage: $ casperjs script.[js|coffee]'
);
phantom
.
exit
(
1
);
}
phantom
.
injectJs
(
phantom
.
args
[
1
]);
phantom
.
casperPath
=
phantom
.
args
[
0
];
phantom
.
casperScript
=
phantom
.
args
[
1
];
phantom
.
casperLibPath
=
fs
.
pathJoin
(
phantom
.
casperPath
,
'lib'
);
[
'casper.js'
,
'clientutils.js'
,
'colorizer.js'
,
'injector.js'
,
'tester.js'
,
'utils.js'
,
'xunit.js'
].
forEach
(
function
(
lib
)
{
phantom
.
injectJs
(
fs
.
pathJoin
(
phantom
.
casperLibPath
,
lib
));
});
phantom
.
injectJs
(
phantom
.
args
[
1
]);
})(
phantom
);
...
...
lib/casper.js
View file @
4e7d738
...
...
@@ -56,7 +56,10 @@
onStepTimeout
:
null
,
onTimeout
:
null
,
page
:
null
,
pageSettings
:
{
userAgent
:
DEFAULT_USER_AGENT
},
pageSettings
:
{
localToRemoteUrlAccessEnabled
:
true
,
userAgent
:
DEFAULT_USER_AGENT
},
stepTimeout
:
null
,
timeout
:
null
,
verbose
:
false
...
...
lib/cli.js
View file @
4e7d738
/**
* Phantom args parsing utilities.
*
*/
(
function
(
phantom
)
{
phantom
.
Casper
.
Cli
=
function
()
{
/**
* Extract current named parameters passed to the phantom script through
* the command line. Named arguments are of the form --foo=bar ou --foo
*
*/
this
.
named
=
phantom
.
args
.
forEach
(
function
(
arg
)
{
if
(
arg
.
indexOf
(
'--'
)
===
0
)
{
var
match
=
/--
(
.*
)
=
(
.*
)\s?
/i
.
exec
(
arg
);
if
(
match
)
{
params
[
match
[
1
]]
=
match
[
2
];
}
else
{
var
match2
=
/--
(
.*
)\s?
/i
.
exec
(
arg
);
if
(
match2
)
{
params
[
match2
[
1
]]
=
true
;
}
}
}
});
/**
* Checks that the specified named arguments have been passed to current
* phantom script. Dies on failure by default, but you can provide an
* onError callback for hooking on fail and do what you want.
*
*/
this
.
requireNamedArgs
=
function
(
list
,
onError
)
{
var
missing
=
[],
params
=
phantom
.
extractNamedArgs
();
for
(
var
i
=
0
;
i
<
list
.
length
;
i
++
)
{
var
name
=
list
[
i
];
if
(
!
params
.
hasOwnProperty
(
name
))
{
missing
.
push
(
name
);
}
}
if
(
missing
.
length
>
0
)
{
if
(
typeof
(
onError
)
===
"function"
)
{
onError
(
missing
);
}
else
{
var
s
=
missing
.
length
>
1
?
'are'
:
'is a'
;
console
.
log
(
JSON
.
stringify
({
status
:
"error"
,
message
:
'"'
+
(
missing
.
join
(
'", "'
))
+
'" '
+
s
+
' required named parameters.'
},
null
,
' '
));
phantom
.
exit
(
1
);
}
}
};
};
})(
phantom
);
...
...
lib/tester.js
View file @
4e7d738
...
...
@@ -314,7 +314,7 @@
var
entries
=
fs
.
list
(
dir
).
filter
(
function
(
entry
)
{
return
entry
!==
'.'
&&
entry
!==
'..'
;
}).
map
(
function
(
entry
)
{
return
fs
.
absolute
(
pathJoin
(
dir
,
entry
));
return
fs
.
absolute
(
fs
.
pathJoin
(
dir
,
entry
));
});
entries
.
forEach
(
function
(
entry
)
{
if
(
fs
.
isDirectory
(
entry
))
{
...
...
@@ -322,7 +322,7 @@
}
});
return
entries
.
filter
(
function
(
entry
)
{
return
isJsFile
(
fs
.
absolute
(
pathJoin
(
dir
,
entry
)));
return
isJsFile
(
fs
.
absolute
(
fs
.
pathJoin
(
dir
,
entry
)));
});
};
...
...
tests/run.js
View file @
4e7d738
//phantom.injectJs('casper.js');
phantom
.
injectJs
(
'lib/vendors/esprima.js'
);
var
fs
=
require
(
'fs'
);
phantom
.
injectJs
(
fs
.
pathJoin
(
phantom
.
casperLibPath
,
'vendors'
,
'esprima.js'
));
var
casper
=
new
phantom
.
Casper
({
faultTolerant
:
false
,
verbose
:
true
...
...
@@ -11,7 +11,18 @@ var tests = [];
if
(
phantom
.
args
.
length
>
2
&&
fs
.
isFile
(
phantom
.
args
[
2
]))
{
tests
=
[
phantom
.
args
[
2
]];
}
else
{
tests
=
[
fs
.
absolute
(
pathJoin
(
casperLibPath
,
'..'
,
'tests'
,
'suites'
))];
tests
=
[
fs
.
absolute
(
fs
.
pathJoin
(
phantom
.
casperLibPath
,
'..'
,
'tests'
,
'suites'
))];
}
casper
.
test
.
runSuites
.
apply
(
casper
.
test
,
tests
);
\ No newline at end of file
// Overriding Casper.open to prefix all test urls
phantom
.
Casper
.
extend
({
open
:
function
(
location
,
options
)
{
options
=
isType
(
options
,
"object"
)
?
options
:
{};
this
.
requestUrl
=
location
;
var
url
=
'file://'
+
phantom
.
casperPath
+
'/'
+
location
;
this
.
page
.
open
(
url
);
return
this
;
}
});
casper
.
test
.
runSuites
.
apply
(
casper
.
test
,
tests
);
...
...
tests/suites/casper/encode.js
View file @
4e7d738
...
...
@@ -2,7 +2,7 @@
t
.
comment
(
'Casper.base64encode()'
);
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
var
image
=
self
.
base64encode
(
'file://'
+
phantom
.
libraryPath
+
'
/site/images/phantom.png'
);
var
image
=
self
.
base64encode
(
'file://'
+
phantom
.
casperPath
+
'/tests
/site/images/phantom.png'
);
t
.
assertEquals
(
image
.
length
,
6160
,
'Casper.base64encode() can retrieve base64 contents'
);
});
...
...
Please
register
or
sign in
to post a comment