Making casperjs work with slimerjs on Windows

Problem

Trying to use casperjs version 1.1.0-beta3 with slimerjs version 0.9.1 on a Windows 7 machine with the command

casperjs --engine=slimerjs

results in two errors:

  1. CLI: The command “Files” was not found. (or something like that)
  2. Popup: Couldn’t read application.ini

Reasons

The command “Files” was not found.

slimerjs uses an environment variable SLIMERJSLAUNCHER to contain the path to the Firefox executable. On my environment that is “C:\Program Files (x86)\Mozilla Firefox\firefox.exe”.

Since it usually contains spaces it needs to be wrapped in quotes. That is, presumably, why the developers used

SET SLIMERJSLAUNCHER="%SLIMERJSLAUNCHER%"

at the top of their slimerjs.bat. Now, if you set the environment variable to include quotes in the first place, or if the batch file is executed twice in the same CLI session, it suddenly looks like that: “”C:\Program Files (x86)\Mozilla Firefox\firefox.exe””.

Couldn’t read application.ini

Firefox needs an application.ini to run. In the slimerjs folder there is one. If using slimerjs standalone this is fine as slimerjs.bat contains

SET SLIMERDIR=%~dp0

which is the path to the executing batch file.

When executing from casperjs, however, this fails, and %~dp0 is set to the working directory (where you execute the script).

Solution

I had to “hack” the slimerjs.bat to make it work standalone and with casperjs.

  1. Open slimerjs.bat and replace around line 3
    SET SLIMERJSLAUNCHER="%SLIMERJSLAUNCHER%"
    with
    SET SLIMERJSLAUNCHER=%SLIMERJSLAUNCHER%
    and make sure your environment variable includes the necessary quotes.
  2. Add a new environment variable called SLIMERDIR and set it to your slimerjs directory. Now in slimerjs.bat replace around line 7
    SET SLIMERDIR=%~dp0
    with
    if not exist %SLIMERDIR% (
    SET SLIMERDIR=%~dp0
    )

This might not be the cleanest solutions but they work. Hopefully these issues will be resolved in future versions of casperjs/slimerjs.