0

I would like to call the nodejs require function on a node module installed as a bower dependency (found in bower.json and not installed with npm).

bower.json:

...
  "dependencies": {
    "casperjs": "git@github.com:n1k0/casperjs.git",

actual code snippet I want to use:

    var casper = require('casperjs').create();

Is it possible ? I tried to call also (targeting the node module from the bower component directory):

    var casper = require('../casperjs').create();
B2F
  • 255
  • 2
  • 10

1 Answers1

1

CasperJS is not a node module. It is only installed through npm for convenience. You should look into SpookyJS or Nightmare which are actual node modules that provide a high level API for web automation.

CasperJS gets most of its modules from PhantomJS (or SlimerJS) which are similar, but distinct from the node modules (mainly fs). So problems like these arise: Error: Cannot find module 'libxmljs'

Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • Interesting, then how can I use the answer of this question http://stackoverflow.com/questions/11604611/what-does-then-really-mean-in-casperjs/11957919#11957919 ? I would like to use "var casper = require('casper').create();" to run multiple casper instances in parallel, see also https://groups.google.com/forum/#!topic/casperjs/Scx4Cjqp7hE/discussion. – B2F Dec 06 '14 at 14:48
  • Write your CasperJS script and [spawn](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) multiple instances. – Artjom B. Dec 06 '14 at 15:15
  • You can also look into [those](http://stackoverflow.com/questions/24880671/how-to-open-a-new-tab-in-casperjs) [few](http://stackoverflow.com/questions/15437512/running-multiple-instances-of-casperjs) [questions](http://stackoverflow.com/questions/24315512/how-to-test-two-interacting-browsers-e-g-chat-app). – Artjom B. Dec 06 '14 at 15:32
  • Since I call my scrpit with the casperjs commandline, I ended up using "new casper.constructor()" instead of "require('casper').create();" it's the only thing I got working so far (the tricky part seems to be my core logic is in code exposed via a nodejs exports statement). Thanks for the hints ! – B2F Dec 06 '14 at 20:00