PhantomCSS 屏幕截图在 for 循环内无法正常工作

PhantomCSS screenshot not working correctly inside for loop

我想在每个页面上截屏。为了导航到不同的页面,有一个函数 moveNext()。当我签入控制台时,我能够看到它按顺序导航到所有页面。但是,它不是在每个页面同时截取屏幕截图,而是对最后一页截取多个屏幕截图。 casperjs 是否提供回调或等待选项?

casper.then(function () {
            for (var currentPage = startPage; currentPage < lastPage; currentPage++) {              
                this.page.evaluate(function(currentPage) {
                    moveNext(currentPage);
                }, currentPage);
                phantomcss.screenshot('html', 'screenshot');
                console.log(currentPage);
            }
        });

for 循环无法运行,因为它太快了。你可以使用类似的东西:

var casper = require('casper').create({
    verbose: true,
    logLevel: 'debug',
    viewportSize:{width: 1600, height: 900}
});
var currentPage = 0,lastPage=5;
casper
     .start()
            .then(function to_call() {
                      if(currentPage<lastPage){
                         currentPage++;
                       /*  this.page.evaluate(function(currentPage) {
                         moveNext(currentPage);
                         }, currentPage);
                         phantomcss.screenshot('html', 'screenshot');*/
                         this.echo("The currentPage number is: "+currentPage,"INFO");
               this.wait(3000).then(to_call)
               }

        })

 .run();
function captureScreenshot(width, height, device, startPage, lastPage) {
        casper.viewport(width, height);

        casper.then(function () {
            var currentPage = startPage - 1;

            /* Capture screenshot of footer */
            phantomcss.screenshot('footer', 'footer');

            /* Capture screenshot of header */
            phantomcss.screenshot('header', 'header');

            /* Capture main content screenshot */
            casper.repeat(lastPage, function () {
                this.page.evaluate(function (currentPage) {
                    moveNext(currentPage);
                }, ++currentPage);

                this.wait(8000, function () {
                    phantomcss.screenshot('#NavForm > .container', 'main-content');
                });
            });
        });
}