How to import other javascript module in PhantomJS or CasperJS

Robert Zaremba picture Robert Zaremba · Jul 16, 2013 · Viewed 11.2k times · Source

I'm trying to build a functional test using CasperJS. caseperjs is run by a backend test suite using the following command:

PHANTOMJS_EXECUTABLE=../client/node_modules/phantomjs/bin/phantomjs  ../client/ext_modules/casperjs/bin/casperjs test ../client/test/functional/init.coffee

In init.coffee I want to import/include other module (file) which seats just next to it. How to do it?

The following doesn't works:

require("user")

All I want is to get a content from other file into init.coffee

Answer

Mark Simon picture Mark Simon · Jan 7, 2014

After trying a number of the other suggestions (each expected to work in the context of their corresponding environments), hit on this solution:

phantom.page.injectJs( 'script.js');