Because you need to learn a bit. Casperjs,casperjs is an open source navigation script processing and testing tool, written based on PHANTOMJS (front end Automated test tool). Because Casperjs is dependent on PHANTOMJS, it is necessary to install PHANTOMJS.
Phantomjs best to download the latest version, because the online version is more, so I found a newer version available for download, is 2.0.0 version. You can find the appropriate download resources on the CSDN.
After the PHANTOMJS installation is complete, you need to write the installation path of the PHANTOMJS to the environment variables in Windows. The process is no longer detailed here.
Installation of Casperjs:
I'm using the 1.1 version of Casperjs, which is a good compatibility.
Add the Casperjs installation path to the environment variable path, for example "C:\casperjs\bin"
So we can use the CASPERJS.
The simple procedure to use is:
Use the console command window to go to your Casperjs installation path (in the Bin folder), and then call the appropriate JS file.
To illustrate:
Open cmd to go to the installation path of your CASPERJS (you can also open the installation path of your Casperjs by first
Then shift-right-click to open the Command window here and use the Invoke statement
Casperjs Myscript.js
Complete the use of CASPERJS.
You may encounter Phantomjs and Casperjs incompatibilities in the course of use, such as Casperjs
Needs Phantomjs v1.x's error,
Casperjs not supported PHANTOMJS 2.x version solution No comments
Problems encountered:
First, after the installation completes, the direct operation error is as follows:
1 |
CasperJS needs PhantomJS v1.x |
Solution, remove the Casperjs version limit code, the code is located in the directory casperjs\bin\bootstrap.js, to remove the code, of course you can also replace the following:
123456789101112 |
//需删除或替换的代码块
(
function
(version) {
// required version check
if (version.major !== 1) {
return __die(
‘CasperJS needs PhantomJS v1.x‘
);
}
if (version.minor < 8) {
return __die(
‘CasperJS needs at least PhantomJS v1.8 or later.‘
);
}
if (version.minor === 8 && version.patch < 1) {
return __die(
‘CasperJS needs at least PhantomJS v1.8.1 or later.‘
);
}
})(phantom.version);
|
If replaced, use the following code
1234567891011121314 |
(
function (version) {
// required version check
if (version.major === 1) {
if (version.minor < 8) {
return __die(
‘CasperJS needs at least PhantomJS v1.8 or later.‘
);
}
if (version.minor === 8 && version.patch < 1) {
return __die(
‘CasperJS needs at least PhantomJS v1.8.1 or later.‘
);
}
}
else if (version.major === 2) {
console.log(
"Warning PhantomJS v2.0 not yet released. There will not be any official support for any bugs until stable version is released!"
);
}
else return __die(
‘CasperJS needs PhantomJS v1.x or v2.x‘
);
})(phantom.version);
|
Once the operation is complete, running again reveals the following error:
1 |
Couldn‘t find nor compute phantom.casperPath, exiting. |
Still need to modify the above Casperjs\bin\bootstrap.js file, add the following code above the file:
1234 |
var system = require( ‘system‘ ); var argsdeprecated = system.args; argsdeprecated.shift(); phantom.args = argsdeprecated; |
At this point, it can run properly!
Reference article:
Http://stackoverflow.com/questions/28656768/issues-running-casperjs-with-phantomjs2-0-0-on-mac-yosemite
https://github.com/n1k0/casperjs/issues/1150
Install Casperjs under Windows