How to organize and require code across different files when using casperjs module?

23 views
Skip to first unread message

Howard T

unread,
Dec 1, 2016, 2:14:16 PM12/1/16
to CasperJS
Hi,

I currently run myfile.js with casperjs ./myfile.js in the CLI but myfile.js has just so many lines of code that I want to split it up across different files. The issue is how might I require different files from the main file and ensure the casper tasks run in the correct order I want them to?

Any advice would be hugely appreciated, thanks.

Best Regards,
Howard

philippe....@oscaro.com

unread,
Dec 6, 2016, 9:13:18 AM12/6/16
to CasperJS
To split your code in different files you can use

phantom.injectJs('../utils/XXXXX.js');

In XXXXX.js you can define several functions and call them in the main file

/**
* myFunction1()
*/
casper.
myFunction1= function() {
    if (...) {
        ...
    } else {

        ...
    }
};


Reply all
Reply to author
Forward
0 new messages