To be clear, I want to use sugar.js extensions in my casperJS script (as distinct from it being part of the web site being tested).
I am using casperJS in test mode (i.e. casperjs test myscript.js) if that makes any difference.
To be clear, I want to use sugar.js extensions in my casperJS script (as distinct from it being part of the web site being tested).
I am using casperJS in test mode (i.e. casperjs test myscript.js) if that makes any difference.
On
Just an addendum to Artjom's answer; when using SlimerJS as the engine it hangs when using require. I got it working (with both PhantomJS and SlimerJS) using the following:
var fs = require('fs');
var sugarJS = fs.read("/path/to/sugar.min.js");
eval(sugarJS);
as a drop-in replacement for:
require("/path/to/sugar.min");
Sugar is basically a support library. It does not export any function, but adds functions to the various types of objects of a JavaScript runtime.
Steps:
require("sugar.min");to execute the file directly or from another directoryrequire("./relativePath/sugar.min");.The following complete script shows that it works:
requireis usually for loading modules, but since Sugar does not export anything it is just executed. An alternative would be reading the file withfs.readandeval.