O'Reilly logo

Instant Testing with CasperJS by Éric Bréhault

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing advanced tests (Intermediate)

This recipe will detail how to simulate rich web interactions using CasperJS, in order to achieve more complex testing.

How to do it...

The following sections cover the various steps in writing advanced tests.

Downloading files

First, let's learn how to download files. The most common way to download a file from a web page is by providing a link to this file as follows (example4.html):

<html><body>
   <h1>My example</h1>
   <a id="link-to-text" href="files/text.txt">Download a text</a>
   <a id="link-to-pdf" href="files/text.pdf">Download a PDF</a>
</body></html>

Now, let's create the following CasperJS script (example4.js):

var casper = require('casper').create(); casper.start('http://localhost:8000/example4.html', function() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required