Lets say I have an array of urls. I dont want to use thenOpen function . Since it waits for every previous url to be loaded and it decreases load time .
casper.each(hrefs,function(self,href){
self.thenOpen(href,function(){ });
self.then(function(){
// Selectors
});
});
What methods would u use to spend much less compared to above method ? Would it be efficient to create multiple instances store in the db and then fetch ... but this is alot of headache . And also would like u also to answer in general would I have problems when I run multiple instances of the same js file simultaneously ?
If you don't care about synchronizing behavior between all the URLs that you are opening, then you should start multiple instances of casper for each URL. Here is an example:
var casperActions = {
href1: function (casper) {
casper.start(address, function() {...});
// tests and what not for href1
casper.run(function() {...});
},
href2: function (casper) {
casper.start(address, function() {...});
// tests and what not for href2
casper.run(function() {...});
},
...
};
['href1', 'href2', ...].each(function(href) {
var casper1 = require('casper').create();
casperActions[href](casper);
});
Each instance would run independently of each other, but it would allow you to hit many URLs simultaneously.
If you want to wait for each operation being finished to sequence an array of steps, look at this sample shipping with casper: https://github.com/n1k0/casperjs/blob/1.0/samples/multirun.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With