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)