
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
grunt-casper
Advanced tools

Run CasperJS Scripts/Functional Tests
If You need Casper 1.0 Support - Please Check out this tag @note : You no longer need PhantomJS/CasperJS binaries installed. They are now managed by npm
This task makes use of PhantomJS to drive the casperJS scripts in a headless manner.
You will need to install phantomjs, with a fairly simple package install After phantomjs is installed, you will need to install casperjs
Now install the grunt task
npm install grunt-casper --save
CasperJS is a navigation scripting & testing utility for PhantomJS. It eases the process of defining a full navigation scenario and provides useful high-level functions, methods & syntaxic sugar for doing common tasks in a headless browser.
If you haven't used casperjs before, be sure to check out the Get Started guide, as it explains how to create your first test case.
Run this task with the grunt casper command.
This task is a multi task so any targets, files and options should be specified according to the [multi task][] documentation.
Type: String || Function
The 'dest' option in Grunt's configuration is passed as the --save option to casper, allowing you to access your destination programmatically. If passed as a function, the return value will be used.
Type: Boolean
Default: false
Run the casperjs script(s) in test mode. Thus allowing you to split up your tests (casperjs test tests/)
Type: String
Default: undefined
Comma separated list of scripts to "include" before executing tests.
Type: String
Default: undefined
Scripts to be executed before the test suite
Type: String
Default: undefined
Scripts to be executed after the test suite
Type: Boolean
Default: false
Output log messages directly to the console
Type: String
Default: error
Options: debug info warning error
Sets the casperjs logging level
Type: Boolean
Default: false
Terminate as soon as a first failure is encountered.
Type: Boolean
Default: false
Create a more concise output of the test suite.
Type: String
Default: phantomjs
Specify Browser Engine (phantomjs|slimerjs)
Type: Number
Default: How many test files to run concurrently (1-10)
Type: Boolean
Default: Run tests in Parallel instead of Series
Basic usage
casper : {
yourTask : {
options : {
test : true
},
files : {
'xunit/casper-results.xml' : ['test/functionalTests.js']
}
}
}
Basic Parallel usage
casper : {
yourTask : {
options : {
test : true,
parallel : true,
concurrency : 5
},
files : {
'xunit/casper-results.xml' : ['test/functionalTests.js'],
'xunit/casper-results-2.xml' : ['test/functionalTests2.js'],
}
}
}
Global options and custom destination
casper : {
options : {
test : true,
includes : 'path/to/inc.js',
post : 'path/to/post.js',
pre : 'path/to/pre.js',
'log-level' : 'warning',
'fail-fast' : true,
concise : true,
engine : 'slimerjs'
},
yourTask : {
src: ['path/to/tests/*_test.js'],
dest : function(input) {
return input.replace(/\.js$/,'.xml');
}
}
}
CasperJS supports options and arguments on the command line.
casperjs script.js baz --foo=bar
Grunt tasks can accept additional arguments and grunt-casper will pass these through to CasperJS, for instance
grunt casper:yourTask:baz:--foo=bar
will pass baz as an argument and foo as an option with a value of bar. These are then available in your CasperJS script
casper.cli.args.indexOf('baz'); // 0
casper.cli.options.foo; //bar
Arguments can also be specified in the Task Options Object
casper : {
options : {
args : ['foo', 'bar']
}
}
Arguments and options will be ignored in test mode as CasperJS does not support them.
You may also override the location of the PhantomJS and CasperJS binaries like so:
process.env.PHANTOMJS_EXECUTABLE = '/path/to/phantomjs'; process.env.CASPERJS_EXECUTABLE = '/path/to/casperjs';
The CasperJS Binary, by default, is loaded from the local ./node_modules directory and has a fallback to look in the global node_modules directory (/usr/local/lib/node_modules)
Task submitted by Chris Miller
FAQs
Run Casper CLI Scripts With Grunt
We found that grunt-casper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.