Skip to content

The Osirium PAM casper module

This section covers:

Introduction

Osirium PAM provides a custom module to aid in the development of CasperJS tasks. The library makes it easy to write CasperJS tasks that adhere to Osirium PAM expected standard.

By default, Osirium PAM expects that parameters will be passed into the task on stdin. For testing, it is possible to hard code the parameters.

Loading parameters

The first thing that a CasperJS task will do is load parameters. This can be done in two ways: hard coding, or receiving them through stdin at runtime.

To hard code your parameters, add an "osirium" section to the CasperJS standard options object before you require the Osirium PAM module.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   var casper = require('casper').create({
       verbose: true,
       logLevel: 'info',
       onError: function(self, m) {   // Any "error" level message will be written
           console.log('FATAL:' + m); // on the console output and PhantomJS will
           self.exit();               // terminate
       },
       pageSettings: {
           loadImages: true,
           loadPlugins: false,
           userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
       },
       viewportSize: {
           width: 1024,
           height: 768
       },
       osirium: {
           O_LOG_LEVEL: "DEBUG",
           username: "exampleuser",
           password: "examplepass"
       }
   });
   var osirium = require('osirium');

For use within Osirium PAM parameters must be read from stdin. This is carried out automatically when importing the Osirium PAM module, so your file can simply look like this:

1
2
   var casper = require('casper').create();
   require('osirium');

Note

It is not required to store a reference to the Osirium PAM as a variable: it attaches functions to the casper object.

Whichever method you use, your task parameters will be available through casper.options.osirium.

API

Parameters

  • description (str) : A short description of the screenshot. Added to the screenshot file name.

  • logLevel (str) : Optional argument dictating the log level at which this screenshot should be displayed. Default is DEBUG.

Save a screenshot of the page that Casper is currently seeing to the task log directory, if the current log level is equal to the given logLevel.

Screenshots will be visible in the task log.