I use phantomjs to test many pages and try to make my code cleaner. Is it possible to execute page.open and call page.evaluate from some other function or module. Now:
page.open(ADDRESS, function(status) { if (status == 'success') { page.evaluate(function() { return document.querySelector('.error'); ...... do some more checks }): .....Run some other code }
What I would like to do:
file check.js : exports.check = function() { page.evaluate(function() { return document.querySelector('.error'); ...... do some more checks }):
And in main.js or other files, I just call this function check.js to do the checks. It probably needs to call this function by reference, but I'm not sure how to do it. If this can be done, all the sizes of my files will decrease, and the code will become more readable.
source share