Casperjs is a wonderful open source navigation, scripting and testing utility written in JS which uses PhantomJS webkit , which is a headless browser. It simplifies the process of defining a full navigation scenario and provides some high level methods for doing tasks such as – entering text, clicking, logging, navigation and logging events.
I had to spend some days to get my first test case running, so here I am making my notes which will benefit me in the longer run. ( In case you have more info, please leave a comment)
1. Download and set your environment paths for casperjs and phantomjs ( refer – previous post)
2. Create a folder say C:\JSplayground ( in my case) which will house your casperjs cases.
3. You can either use VS to write your new casperjs script or even a simple tool notepad++ will suffice.
4. Below is the code, I used, which you can also use to get your first case running. It’s pretty straight forward thing. You can copy the code and create a file with extension .js . In my case – sampletest.js
5. From the above code, If you have not figured out already, setting the capturePage as true or false drops the screen shot of the application under test in the same folder as your .js file. Ensure that the casper.userAgent is set to the same , as I was searching for long since some websites render and open differently for different browsers.
6. Once you have created your .js file, you can run now this script from your location by using the below command
7. I have given the option of using –ignore-ssl-errors=yes –ssl-protocol=any so that even if your url is https:// your tests will run. BTB, Phantomjs had really bad support for SSL until 2.0 release. ( unfortunately I am on a newer version of Phantomjs and Casperjs is not equipped to handle 2.0. However, thanks to rdpanek , he has released a fix for CasperJS bootstrap/ Phantomjs 2.0 fix)