Casperjs Practical Notes (4)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.