I know there is a documentation from CasperJS website about how to install CasperJS on Windows, but bear with me these guys only explained for the pros only.
If you
after a 3days work, i managed to get it work the problem was with the path and the installation of phantom. i had made the path to a folder but the installation was pointing to the exe file all i had to do was to put the exe file into a folder phantomjs and that was it thank for your help all.
Fast forward to 2015... 5-steps win7 howto:
PS me> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
choco install git -y
choco install phantomjs -y
git clone https://github.com/n1k0/casperjs -b phantomjs-2
casperjs/bin
to PATHDone. You can now casperjs --version
and live happily ever after.
Ok guys. So I think this thread needs refreshing for 2018!
So with npm
, the effort is reduced significantly. Given that you have npm
installed, open terminal and go to your project:
cd your_project_name
Now install casperjs. Use --save-dev
, --save
, -g
or none as needed:
npm install --save-dev casperjs
Now install phantomjs. To do this, you should install phantomjs-prebuilt, because PhantomJS team changed their package name:
npm install --save-dev phantomjs-prebuilt
Run your spec:
casperjs your_spec_name.js
As of CasperJS 1.1.0-DEV Beta 3 you should use this PATH: C:\casperjs\batchbin
even though the documentation found here states you need to use C:\casperjs\bin
The reason to this is because C:\casperjs\batchbin
includes a .BAT which C:\casperjs\bin
does not include anything except some.js
files.
Just in case you're using a notebook with dual graphic cards like I do: choose one of them to prevent issues. This article helped me out:
casperJS not finishing on windows
the casperJS documentation is pretty clear about it but I had no clue what to do until I read the notice above.
I itemize below the method that has served my needs on both my personal Windows and Ubuntu work PC. DO note that my method doesn't fiddle with PATH settings but involves a command you could save somewhere & copy and paste as needed:
Step 1: Gather the prerequisites
Step 2: Running your script
Experimental config.js and first.js are listed below:
config.json
{"sslProtocol": "any", "cookiesFile": "biscuit", "maxDiskCacheSize": 1000, "diskCache": true}
first.js
var casper = require('casper').create({
pageSettings: {
loadImages: false,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
}
});
var url = "http://casperjs.org/";
casper.start(url).wait(60 * 1000 * 1, function() {
casper.echo('1 min has passed');
casper.capture('casperjs.png');
casper.exit();
});
casper.run();
Addendum: download and save the details of screenshots.js and run it as
phantomjs.exe --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli screenshots.js http://phantomjs.org
Run Tests: download & save the details of picturefill-test.js and run it as
phantomjs.exe --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs test --cli picturefill-test.js