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)