I am trying to use CasperJS to automate some steps that usually require a lot of time to do. Basically I need to login to our CMS and check if some plugins are installed. If they are then just update them but if they’re not then create them. I managed to login and get to the page with the list of the plugins but I got into trouble here. Here’s what I need to do, in pseudocode:
for every plugin defined in my config file
populate the search plugins form and submit it
evaluate if the response contains my plugin
Here is the code
casper.thenOpen(snippetsUrl, function() {
console.log(colorizer.colorize("###############PROCESSING SNIPPETS###################", 'ERROR'));
this.capture('snippets.png');
this.each(Config.snippets.station, function(self, snippet) {
self.fill('form[id="changelist-search"]', {q: snippet.name}, true);
self.then(function() {
this.capture(snippet.name + '.png');
})
});
});
What happens is that my form gets submitted multiple times in a row and on my “then” step i end up capturing the same page multiple times…How to resolve this?
Try this:
The reason why your initial code did not work is that Capser’s
thendeclares a deferred execution step. If unwinded, your code did actually the following:The resulting code has all steps placed into the queue, so they are executed in proper order.