Test module for CASPERJS
Casper.test.begin performs a complete set of test actions, but the object this is not Capser but test!
Only the test object itself has Casper attribute, plus the attribute provided by the test module (which provides many APIs related to testing).
Casper objects have a lot of options, here are the Options settings, options allow us to set some defaults, useragent, custom features, and so on.
Examples are as follows:
Casper.options.pageSettings ={loadimages:true, Loadplugins:true, useragent:' Mozilla/5.0 (Linux; U Android 4.3; En-us; sm-n900t build/jss15j) applewebkit/534.30 (khtml, like Gecko) version/4.0 Mobile safari/534.30 '};casper.options.verbose=true; Casper.options.logLevel= "Debug"; Casper.on ("Page.error",function(_err, _trace) { This. log (_err, "error");}); Casper.on ("Remote.message",function(_msg) { This. log (_msg, "warning");});
For example, LogLevel used to set the log level, there are 4 values: debug,info,warning,error;
For example, using on Listener event "Page.error", can be used to crawl JS script error;
The response to the HTTP request is also handled, and there are two ways to do so, the code is as follows:
Casper.on ("http.status.400",function(_resource) { This. log ("Remote http.status.400 occur.", "Error"); This. log (_resource.url, "error");}); Casper.options.httpStatusHandlers= { 400:function(self, _resource) { This. log (CASPER._IMPOR_MSG_STR1, "error"); This. log ("Remote http.status.400 occur.", "Error"); This. log (_resource.url, "error"); This. log (CASPER._IMPOR_MSG_STR2, "error"); }};
In the process of code execution, it is necessary to output information, just fine; there are three ways: casper.echo,casper.log,test.info
One of the test.info with a parameter, is "want to say words";
And Casper.echo can take 2 parameters: "What to say" and "important level" (debug,info,warning,error);
Casper.log can take 3 parameters: "Words to say", "important level", "source" (phantom or Casper);
Well, I feel very generous.
Casperjs Practical Notes (4)