Casperjs Practical Notes (2)

Source: Internet
Author: User

The code is written in a JS file, executed in the following way:

Casperjs Test Xxx.js

But after more than 1500 lines of code, only I can see clearly, must be split (independent file & logic reuse)!

How do you do it after splitting? as follows:

Casperjs test--includes=1.js,2.js,3,js,4.js  testcase_code1.js--xunit=tesecase01_result.xml

The file 1.js,2.js,3.js,4.js is the implementation code that is split out, and testcase_code1.js can be used as the execution step code for the test case.

The current part of my test steps is a chain call:

function () {    Casper.start ("http://xx.xx.com");    Casper.then (fun_a). Then (Fun_b). then (Fun_c);    Casper.run (function() {    //    ...     })})

Methods Fun_a, Fun_b, and Fun_c implementations are all splitting out of those files.

Includes includes a long list of files, error-prone, and there is room for optimization to add custom logic from Casperjs's run.js (depending on your project's needs, but I don't have time to do this)

Add a few words of nonsense:

Fun_a These methods if put in Casper.then inside call, can only be an implementation form can not be the execution form;

For example Casper.then (fun_a) is correct but Casper.then (Fun_a (str1, str2)) is definitely wrong!

What do we do? Can not take parameters is not convenient, in fact, in the fun_a implementation of a closed packet return function can be.

Tips: Some methods of implementation are closures, some methods are not closures, a little messy.

Casperjs Practical Notes (2)

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.