Cannot find module 'casper' when invoking through PhantomJS

前端 未结 5 2091
野趣味
野趣味 2021-01-02 14:13

I installed PhantomJS in C:\\xampp\\htdocs\\phantom and also I installed CasperJS in this folder C:\\xampp\\htdocs\\casper

When I tried to run these sample code on c

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 14:56

    If you want to run CasperJS through PhantomJS (since you invoke phantomjs test.js) you need some bootstrapping code at the beginning of the script:

    phantom.casperPath = 'path/to/node_modules/casperjs';
    phantom.injectJs('path/to/node_modules/casperjs/bin/bootstrap.js');
    

    Keep in mind that even on windows, you need to use a forward slash.

    If you need the test environment then you also need the line:

    phantom.casperTest = true;
    

    Everything is taken from this question: Running 'casperjs test' in phantom

    Although this is possible you shouldn't do it. You should invoke CasperJS directly through its executable/batch file in node_modules/casperjs/batchbin.

提交回复
热议问题