Installing CasperJS on Windows: How to do it correctly?

user2075354 picture user2075354 · Feb 15, 2013 · Viewed 26.5k times · Source

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 are new to all this CasperJS and PhantomJS world, you dont stand a chance to understand not even spending two days trying to search the net for a better explanation.

I am working on a project that requires a screenshot of each website listed on my project website, looking around i found out that PhantomJS would be great for this task (website screenshot).

I downloaded PhantomJS and and pasted its phantomjs.exe file in system32 which is working well when i use cmd.exe to send command.

I even managed to grab screenshot with the phantomjs.exe only. but my problem came when i noticed the the workload could be easier when these two work together (CasperJS and PhantomJS) as i can even be able to reduce the size of the screenshot when using CasperJS.

In fact the only use that i want CasperJS for is the limiting of the shot size but since yesterday i have been trying to figure out how to make CasperJS work on Windows but with no avail.

I have downloaded CasperJS and tried to install it in many ways also trying to follow the documentation but nothing.

I changed the CasperJS folder name from its download name to CasperJS as the documantation suggest but when i check in the cmd trying to call some commands, nothing happens.

Anyway to cut the story shot can anyone help me in simple terms considering that i am a newbie to explain how CasperJS can be installed on window or if possible with PhantomJS only how can i re-size the iamge the the program produces lets say if i want a 960 to 400px.

Answer

isimmons picture isimmons · Jul 11, 2013

Poor documentation for windows. http://casperjs.org/installation.html#windows

It starts off assuming you have already installed without telling you how to install.

So here it is if anyone else is confused about this. There is no actual install. It's just extracting zip contents to the right place.

  1. download phantomjs for windows from the phantomjs site (it's a zip with binary inside)
  2. extract the contents to C:\phantomjs
  3. download the casperjs zip file from the casperjs website
  4. extract the contents to C:\casperjs
  5. Now you can add the following to the end your system or user PATH variable

    ;C:\phantomjs;C:\casperjs\batchbin

  6. restart cmd.exe to pick up the new path variable or logout/login if you are running Console2 or Conemu terminal emulator (they won't pick up new paths by a simple close and re-open)

Now in the docs it says to run it like this

casperjs.bat myscript.js

Actually since both phantomjs.exe and casperjs.bat are now in the system PATH you can leave off the extension like this.

casperjs myscript.js

And when running phantomjs.exe just run

phantomjs

One more thing. It really doesn't matter where you install as long as you add that path to the system PATH. I installed to C:\usr\phantomjs and C:\usr\casperjs.