Casperjs Practical Notes (3)

Source: Internet
Author: User

Casperjs the encapsulation and invocation of methods in the project, the second encountered a workflow problem.

There are several methods in other code, such as Fun_a,fun_b,fun_c;

Now that a method calls them, there is a demonstration of the error:

Casper.then (function(){     This. Echo ("XXXX");  This. Wait (function(){         This. Echo ("AAAA"); })     This. Waitforselector (",        function() {Fun_a.call ( This); Fun_b.call ( This, str1, str2); Fun_c.call ( This); }, function(){        }, 100);  This. Wait (100,function(){         This. Echo ("BBBB"); })})

So called, the expected workflow is: AAAA-to-fun_a-fun_b---Fun_c--and BBBB.

But actually running, we find that the execution order of Fun_a, Fun_b and Fun_c is unexpected-- We can think of it as a casperjs bug!

To avoid this problem, you can call this:

Casper.then (function(){     This. Echo ("XXXX");  This. Wait (function(){         This. Echo ("AAAA"); })     This. Waitforselector (",        function(){             This. Wait (Fun_a.bind ( This));  This. Wait (Fun_b.bind ( This));  This. Wait (Fun_c.bind ( This)); }, function(){        }, 100);  This. Wait (100,function(){         This. Echo ("BBBB"); })})

Of course, if fun_b need to take parameters, as stated in the previous article, it is necessary to consider the closure implementation method Fun_b.

(on the network rarely CASPERJS practice, a lot of things to explore their own, the wording may not be professional, welcome criticism correct), greatly appreciated!

Casperjs Practical Notes (3)

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.