I'm trying to open a couple of URLs in sequence with Casperjs.
Here is a simplified version of my actual code.
casper = require('casper').create()
casper.start()
casper.then () ->
items = ['http://www.google.com', 'http://www.yahoo.com']
for item, idx in items
this.open item
this.then ((idx) ->
() ->
this.capture idx + '.png')(idx)
casper.run()
In my actual code, the items array is generated at runtime. I expect that this code will provide screenshots of google.com and yahoo.com, but actually both screen shots end up as yahoo.com. I feel like this has something to do with creating a closure inside a loop, but I can't see how. When open
is called, item
refers to a specific string. I'm never closing over it, am I?