Como dizer ao CasperJS para percorrer uma série de páginas

Eu tento fazer o CasperJS alcançar o seguinte:

Percorra uma série de páginas nomeadas sequencialmente por data.Em cada página, localize um link em PDF.Faça o download do PDF.

Eu tenho um código de trabalho, mas não entendo como o CasperJS está passando pela sequência de eventos.

Por exemplo, no exemplo de código abaixo, o CasperJS tenta processar a etapa 2 e lança um "ReferenceError: Impossível encontrar a variável: formDate", enquanto a etapa 1 não é executada por algum motivo.

O que há de errado com o meu raciocínio?

Parece-me que owhile loop é executado em uma velocidade diferente dacasper.then métodos.

casper.start();

casper.thenOpen('http://www.example.com', function() {
    this.echo(this.getTitle());
});

casper.then(function() {

    var start = new Date('2013-01-01T00:00:00');
    var end = new Date('2013-01-31T00:00:00');

    while(start < end) {

          // step 1: define formDate  
          casper.then(function() {
            var formDate = start.getFullYear()+"-"+("0" + (start.getMonth() + 1)).slice(-2) +"-"+("0" + start.getDate()).slice(-2) ;
            casper.echo(formDate);

          });

          // Step 2: open the page and download the file
          casper.thenOpen('http://www.example.com/' + formDate, function() {

                        var url = this.getElementAttribute('div#pdffulllink a.pdf', 'href');
                        this.echo(url);
                        this.download(url, 'Downloaded_' + formDate + '.pdf');

          });

          casper.then(function() {
          // Step 3: redefine start
            var newDate = start.setDate(start.getDate() + 1);
            start = new Date(newDate);

          });

    }

});


casper.run(function() {
    this.echo('Done.').exit();
});

questionAnswers(1)

yourAnswerToTheQuestion