1

Anyone know if and how it's possible to run casperjs from within the phantomjs shell (a.k.a InteractiveModeREPL )?

phantomjs shell

I've also tried passing the direct path to the casper.js module and that has not worked either.

Progress/Update:

  • Tried phantomjs.injectJs('C:/casperjs/module/casper.js'); but got Error: Cannot find module 'colorizer' I guess I'm getting close.
  • This gets me closer but still missing path:
    • phantomjs.injectJs('C:/casperjs/module/bin/bootstrap.js')
      • errors out with Cannot find package.json at C:/package.json
    • OK, looks like I can pass the --casper-path option when starting phantomjs (see - casper/bin/bootstrap.js: line 189).
    • OK that worked. (passing the option did not work but setting the path inside of phantom did).
dkinzer
  • 32,179
  • 12
  • 66
  • 85

1 Answers1

3

So to get this stuff to run inside the phantomjs shell first you need to set a casperPath variable in the phantom global object.

phantom.casperPath = "C:/casper";

Then you need to inJect caspers's bootstrap.js file.

phantom.injectJs("C:/casper/bin/bootstrap.js");

Now you can instantiate a casper object and play with it in the shell.

var casper = require("casper").create();

enjoy.

dkinzer
  • 32,179
  • 12
  • 66
  • 85
  • No longer works. See [casper 1.1 upgrading](http://docs.casperjs.org/en/latest/upgrading/1.1.html) and this [more recent question](http://stackoverflow.com/questions/19857139/running-casperjs-test-in-phantom). – Ian Tegebo Feb 05 '14 at 00:09
  • It doesn't work for me . phantomjs 1.9.8 no longer has the casperPath varaible. – huzefa biyawarwala Dec 21 '15 at 07:11
  • Any workaround in 2016 to have interactive mode with casper-1.1.1 and phantomjs 1.9.1 ? – Gilles Quénot Nov 23 '16 at 13:32