Upgrading casperjs to use phantomjs 2.0 from 1.9.8

2019-09-09 19:45发布

问题:

I read that people have found ways to get casperjs to work with phantomjs 2.0 but how could I do the upgrade? For example just swapping out phantomjs folder in /usr/.../casperjs/node_modules/phantomjs with a folder for phantomjs2 doesn't seem to do the trick. I've also made the changes in lib/bootstrap.js to handle the warnings from using 2.0.

I'm using mocha-casperjs to create my tests.

回答1:

If you want to use PhantomJS 2, then you currently need to either

  • install CasperJS from git (which supports PhantomJS 2) and change the fixed path in mocha-casperjs or
  • remove the PhantomJS version checks in CasperJS as seen here

Change the fixed path in mocha-casperjs (in mocha-casperjs/bin/mocha-casperjs) from:

$mcPath/../../casperjs/bin/casperjs $mcPath/cli.js --mocha-casperjs-path=$mcPath/.. $*

to

path/to/casperjs $mcPath/cli.js --mocha-casperjs-path=$mcPath/.. $*

or if casperjs is in the PATH:

casperjs $mcPath/cli.js --mocha-casperjs-path=$mcPath/.. $*

PhantomJS versions

I suggest that you also preserve multiple versions of PhantomJS and switch between them if you need it. Currently there is no official PhantomJS 2 version, so you will need to build it yourself or trust zeevl who seems to have compiled PhantomJS 2 for Linux:

npm -g install phantomjs2